admin
2024-10-17 b30fb8afd3cd6228bda9b182dc412bb3c8daf69c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
                }
            }
 
        });
    }
}