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
package com.yeshi.buwan.util.mq.rabbit.consumer;
 
import com.rabbitmq.client.Channel;
import com.yeshi.buwan.domain.ResourceVideo;
import com.yeshi.buwan.service.imp.ResourceVideoService;
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;
import java.util.List;
 
/**
 * @author hxh
 * @title: QueueHelloWorldListener
 * @description:
 * @date 2024/9/26 13:47
 */
@Component
public class VideoResourceDeleteListener {
    private final static Logger logger = LoggerFactory.getLogger(VideoResourceDeleteListener.class);
 
    @Resource
    private RabbitTemplate rabbitTemplate;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @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 {
                    String videoId = result;
                    //查询资源列表
                    List<ResourceVideo> resourceVideoList = resourceVideoService.getResourceList(videoId);
                    //隐藏视频
                    if (resourceVideoList == null || resourceVideoList.size() == 0)
                        videoInfoService.hiddenVideo(videoId);
                    //更新搜索引擎
                    rabbitmqManager.addSolrMsg(videoId);
                } catch (Exception e) {
                    logger.error("视频资源删除处理出错:" + e.getMessage());
                    logger.error("ID:" + result);
                    throw e;
                }
            }
        });
    }
}