com.spring.boxes.cloud.rocket.RocketTemplate Maven / Gradle / Ivy
The newest version!
package com.spring.boxes.cloud.rocket;
import com.spring.boxes.dollar.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
/**
@Slf4j
public class RocketTemplate {
@Resource(name = "rocketMQTemplate")
private RocketMQTemplate template;
public RocketMQTemplate getTemplate() {
return template;
}
public String buildDestination(String topic, String tag) {
return topic + RocketMqSysConstant.DELIMITER + tag;
}
public SendResult send(String topic, String tag, T message) {
// 注意分隔符
return send(topic + RocketMqSysConstant.DELIMITER + tag, message);
}
public SendResult send(String destination, T message) {
// 设置业务键,此处根据公共的参数进行处理
// 更多的其它基础业务处理...
Message sendMessage = MessageBuilder.withPayload(message).setHeader(RocketMQHeaders.KEYS, message.getKey()).build();
SendResult sendResult = template.syncSend(destination, sendMessage);
// 此处为了方便查看给日志转了json,根据选择选择日志记录方式,例如ELK采集
LOGGER.info("[{}]同步消息[{}]发送结果[{}]", destination, JSONUtils.toJson(message), JSONObject.toJSON(sendResult));
return sendResult;
}
public SendResult send(String topic, String tag, T message, int delayLevel) {
return send(topic + RocketMqSysConstant.DELIMITER + tag, message, delayLevel);
}
public SendResult send(String destination, T message, int delayLevel) {
Message sendMessage = MessageBuilder.withPayload(message).setHeader(RocketMQHeaders.KEYS, message.getKey()).build();
SendResult sendResult = template.syncSend(destination, sendMessage, 3000, delayLevel);
LOGGER.info("[{}]延迟等级[{}]消息[{}]发送结果[{}]", destination, delayLevel, JsonUtil.toJson(message), JsonUtil.toJson(sendResult));
return sendResult;
}
}*/
© 2015 - 2025 Weber Informatics LLC | Privacy Policy