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;
|
}
|
}
|
|
|
}
|