admin
2024-10-16 7fa83e5dd03f7896bd1d1e8c47f5e926ff3d4ba0
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.ks.push.manager.rabbitmq;
 
import com.google.gson.Gson;
import com.ks.push.dto.BPushDeviceDataSet;
import com.ks.push.dto.mq.InvalidDeviceTokenInfo;
import com.ks.push.pojo.DO.PushPlatform;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * @author hxh
 * @title: RabbitmqManager
 * @description: Rabbitmq管理器
 * @date 2024/10/16 13:23
 */
@Component
public class RabbitmqManager {
 
    /**
     * 小米推送队列
     */
    public static String PUSH_XM = "bpush-xm";
    /**
     * 华为推送队列
     */
    public static String PUSH_HUAWEI = "bpush-huawei";
    /**
     * oppo推送队列
     */
    public static String PUSH_OPPO = "bpush-oppo";
    /**
     * vivo推送队列
     */
    public static String PUSH_VIVO = "bpush-vivo";
    /**
     * 魅族推送队列
     */
    public static String PUSH_MZ = "bpush-mz";
 
    /**
     * 极光推送队列
     */
    public static String PUSH_JPUSH = "bpush-jpush";
 
    /**
     * 无效设备队列
     */
    public static String PUSH_TOKEN_INVALID = "bpush-token-invalid";
 
    @Resource
    private RabbitTemplate rabbitTemplate;
 
 
    private String getQueueName(PushPlatform platform) {
        String queueName = null;
        if (platform == PushPlatform.xm) {
            queueName = PUSH_XM;
        } else if (platform == PushPlatform.hw) {
            queueName = PUSH_HUAWEI;
        } else if (platform == PushPlatform.oppo) {
            queueName = PUSH_OPPO;
        } else if (platform == PushPlatform.vivo) {
            queueName = PUSH_VIVO;
        } else if (platform == PushPlatform.mz) {
            queueName = PUSH_MZ;
        }else if (platform == PushPlatform.jpush) {
            queueName = PUSH_JPUSH;
        }
        return queueName;
    }
 
 
    /**
     * 添加到推送队列
     *
     * @param platform
     * @param dataSet
     */
    public void addToPushQueue(PushPlatform platform, BPushDeviceDataSet dataSet) {
        String queueName = getQueueName(platform);
        if (queueName == null) {
            return;
        }
        RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, queueName, new Gson().toJson(dataSet));
    }
 
    /**
     * 发送无效设备消息
     *
     * @param info
     */
    public void addInvalidDevieToken(InvalidDeviceTokenInfo info) {
        if (info == null) {
            return;
        }
        RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, PUSH_TOKEN_INVALID, new Gson().toJson(info));
    }
 
 
    public static class MQMsgConsumeResult {
        private String queueName;
        private Object data;
        private String receiptHandle;
 
        public MQMsgConsumeResult(Object data, String queueName, String receiptHandle) {
            this.data = data;
            this.queueName = queueName;
            this.receiptHandle = receiptHandle;
        }
 
        public Object getData() {
            return data;
        }
 
        public void setData(Object data) {
            this.data = data;
        }
 
        public String getReceiptHandle() {
            return receiptHandle;
        }
 
        public void setReceiptHandle(String receiptHandle) {
            this.receiptHandle = receiptHandle;
        }
 
        public String getQueueName() {
            return queueName;
        }
 
        public void setQueueName(String queueName) {
            this.queueName = queueName;
        }
    }
 
 
}