admin
2020-09-05 d3ebf5b103d4deebd6ffb75f4471a6fddab8d764
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.yeshi.buwan.util.mq;
 
import com.qcloud.cmq.Message;
import com.yeshi.buwan.dto.mq.IqiyiAlbum2MQMsg;
import com.yeshi.buwan.dto.mq.SolrVideoMQMsg;
 
import java.util.ArrayList;
import java.util.List;
 
public class CMQManager {
    private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
    private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
    private static CMQManager cmqManager;
    private static CMQUtil cmqUtil;
    // 搜索引擎
    public static String QUEUENAME_SOLR = "buwan-solr";
    //视频更新-爱奇艺2
    public static String QUEUENAME_VIDEO_UPDATE_IQIYI_2 = "buwan-video-update-iqiyi2";
 
 
    static {
        cmqUtil = CMQUtil.getInstance(secretId, secretKey);
        // 最大消息为1M
        cmqUtil.createQueue(QUEUENAME_SOLR, 1024 * 1024);
        cmqUtil.createQueue(QUEUENAME_VIDEO_UPDATE_IQIYI_2, 1024 * 1024);
    }
 
    public static CMQManager getInstance() {
        if (cmqManager == null)
            cmqManager = new CMQManager();
        return cmqManager;
    }
 
 
    //添加专辑更新消息
    public void addAlbumUpdateMsg(Long id) {
        cmqUtil.sendMsg(QUEUENAME_VIDEO_UPDATE_IQIYI_2, id + "");
    }
 
    //消费专辑更新消息
    public List<IqiyiAlbum2MQMsg> consumeAlbumUpdateMsg(int count) {
        List<IqiyiAlbum2MQMsg> list = new ArrayList<>();
        List<Message> msgList = cmqUtil.recieveMsg(count, QUEUENAME_VIDEO_UPDATE_IQIYI_2);
        if (msgList != null)
            for (Message msg : msgList) {
                IqiyiAlbum2MQMsg mm = new IqiyiAlbum2MQMsg();
                mm.setHandler(msg.receiptHandle);
                mm.setId(Long.parseLong(msg.msgBody));
                list.add(mm);
            }
        return list;
    }
 
    //删除专辑更新消息
    public void deleteAlbumUpdateMsg(String handler) {
        cmqUtil.deleteMsg(QUEUENAME_VIDEO_UPDATE_IQIYI_2, handler);
    }
 
 
    /**
     * 搜索引擎
     * @param id
     */
 
    /**
     * 搜索引擎消息
     *
     * @param id
     */
    public void addSolrMsg(String id) {
        cmqUtil.sendMsg(QUEUENAME_SOLR, id);
    }
 
    public List<SolrVideoMQMsg> consumeSolrMsg(int count) {
        List<SolrVideoMQMsg> list = new ArrayList<>();
        List<Message> msgList = cmqUtil.recieveMsg(count, QUEUENAME_SOLR);
        if (msgList != null)
            for (Message msg : msgList) {
                SolrVideoMQMsg mm = new SolrVideoMQMsg();
                mm.setHandler(msg.receiptHandle);
                mm.setId(msg.msgBody);
                list.add(mm);
            }
        return list;
    }
 
 
    public void deleteSolrMsg(String handler) {
        cmqUtil.deleteMsg(QUEUENAME_SOLR, handler);
    }
 
}