|
@@ -171,6 +171,27 @@ public class RocketMQProducer {
|
|
|
}
|
|
|
Message message = messageBuilder.build();
|
|
|
rocketMQTemplate.sendOneWay(topic, message);
|
|
|
+ log.info("MQ推送成功---topic:{},tag:{},key:{},msg:{}",topic,tag,key, JSONObject.toJSONString(body));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 顺序消费 (计算场景使用)
|
|
|
+ * @param topic 主题名
|
|
|
+ * @param body 消息体
|
|
|
+ */
|
|
|
+ public void sendInOrder(String topic, Object body){
|
|
|
+ this.sendInOrder(topic,"modeling",body);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 顺序消费 计算场景使用)
|
|
|
+ * @param topic 主题名
|
|
|
+ * @param hashKey: 为了保证报到同一个队列中,将消息发送到orderTopic主题上
|
|
|
+ * @param body 消息体
|
|
|
+ */
|
|
|
+ public void sendInOrder(String topic, String hashKey, Object body){
|
|
|
+ log.info("MQ推送消息---topic:{},hashKey:{},msg:{}",topic,hashKey, JSONObject.toJSONString(body));
|
|
|
+ rocketMQTemplate.setMessageQueueSelector((list, message, o) -> list.get(Integer.parseInt(o.toString())));
|
|
|
+ rocketMQTemplate.syncSendOrderly(topic,body,hashKey);
|
|
|
+ log.info("MQ推送成功---topic:{},hashKey:{},msg:{}",topic,hashKey, JSONObject.toJSONString(body));
|
|
|
}
|
|
|
|
|
|
}
|