package com.yeshi.buwan.util.mq.rabbit.consumer;
|
|
import com.google.gson.Gson;
|
import com.rabbitmq.client.Channel;
|
import com.yeshi.buwan.dto.mq.VideoExtraInfoChangeMQMsg;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.util.mq.rabbit.RabbitmqManager;
|
import com.yeshi.buwan.util.mq.rabbit.RabbitmqMsgConsumeUtil;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import java.nio.charset.StandardCharsets;
|
|
/**
|
* @author hxh
|
* @title: QueueHelloWorldListener
|
* @description:
|
* @date 2024/9/26 13:47
|
*/
|
@Component
|
public class VideoUpdateExtrainfoListener {
|
private final static Logger logger = LoggerFactory.getLogger(VideoUpdateExtrainfoListener.class);
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@Resource
|
private RabbitTemplate rabbitTemplate;
|
|
@Resource
|
private RabbitmqManager rabbitmqManager;
|
|
public void onMessage(Message message, Channel channel) throws Exception {
|
RabbitmqMsgConsumeUtil.processMessage(message, channel, rabbitTemplate, () -> {
|
String result = new String(message.getBody(), StandardCharsets.UTF_8);
|
if (!StringUtil.isNullOrEmpty(result)) {
|
try {
|
VideoExtraInfoChangeMQMsg videoExtraInfoChangeMQMsg = new Gson().fromJson(result, VideoExtraInfoChangeMQMsg.class);
|
if (videoExtraInfoChangeMQMsg != null) {
|
switch (videoExtraInfoChangeMQMsg.getType()) {
|
case VideoExtraInfoChangeMQMsg.TYPE_RESOURCE:
|
if (VideoExtraInfoChangeMQMsg.ACTION_DELETE.equalsIgnoreCase(videoExtraInfoChangeMQMsg.getAction())) {//删除视频源
|
rabbitmqManager.addVideoResourceDeleteMsg(videoExtraInfoChangeMQMsg.getVideoId());
|
}
|
break;
|
case VideoExtraInfoChangeMQMsg.TYPE_CATEGORY:
|
break;
|
}
|
videoInfoService.statisticVideoExtraInfo(videoExtraInfoChangeMQMsg.getVideoId());
|
}
|
} catch (Exception e) {
|
logger.error("视频资源删除处理出错:" + e.getMessage());
|
logger.error("ID:" + result);
|
throw e;
|
}
|
}
|
|
});
|
}
|
}
|