|
@@ -35,7 +35,9 @@ public class RabbitMqProducer {
|
|
private RabbitTemplate rabbitTemplate;
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 工作队列模式发送
|
|
|
|
|
|
+ * 工作队列模式发送消息
|
|
|
|
+ * @param queue 队列名
|
|
|
|
+ * @param content 载荷
|
|
*/
|
|
*/
|
|
public void sendByWorkQueue(String queue, Object content){
|
|
public void sendByWorkQueue(String queue, Object content){
|
|
String messageId = UUID.randomUUID().toString();
|
|
String messageId = UUID.randomUUID().toString();
|
|
@@ -47,6 +49,22 @@ public class RabbitMqProducer {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 工作队列模式发送带优先级消息
|
|
|
|
+ * @param queue 队列名
|
|
|
|
+ * @param content 载荷
|
|
|
|
+ * @param priority 优先级,正整数,值越大优先级越高,当值大于队列设置的最大优先级时,效果等同于最大优先级
|
|
|
|
+ */
|
|
|
|
+ public void sendByWorkQueue(String queue, Object content, Integer priority){
|
|
|
|
+ String messageId = UUID.randomUUID().toString();
|
|
|
|
+ log.info("开始发送Mq消息,messageId:{},消息队列:{},消息内容:{}",messageId, queue, new JSONObject(content).toString());
|
|
|
|
+ rabbitTemplate.convertAndSend(queue, content, message -> {
|
|
|
|
+ message.getMessageProperties().setMessageId(messageId);
|
|
|
|
+ message.getMessageProperties().setPriority(priority);
|
|
|
|
+ return message;
|
|
|
|
+ }, new CorrelationData(messageId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 获取队列未被消费的消息数量
|
|
* 获取队列未被消费的消息数量
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|