我使用Rabbit MQ发送和接收JSON消息 我已经使用带有convertAndSend方法的RabbitTemplate实例实现了一个应用程序,如下所示向交换发送消息:
rabbitTemplate.convertAndSend(exchangeNameOut, message.getString(PERSISTENCE_MESSAGE_ROUTING_KEY),
message.getString(PERSISTENCE_MESSAGE_BODY), new CorrelationData(""+analyticRuntime.getId()));
在检索消息时,侧接收器,我已经实现了以下方法:
@RabbitListener(queues = "${rabbit.queue.mail.name}",containerFactory = "rabbitListenerContainerFactory")
public void processMailMessage(Message message) {
log.info("ENTER [processMailMessage] ");
Mail mail;
JSONObject messageBody = new JSONObject(new String(message.getBody()));
String asset = "" + messageBody.get(Constants.PERSISTENCE_MESSAGE_ASSET_ID_KEY);
String body = "" + messageBody.get(Constants.PERSISTENCE_MESSAGE_EVENT_KEY);
String alarms = "";
log.info("[processMailMessage] message.getMessageProperties().getCorrelationId() : " + message.getMessageProperties().getCorrelationId()";
}
问题是:
由于
答案 0 :(得分:4)
没有;相关数据用于关联发送者的发布者确认;它与相关Id属性无关。
使用MessagePostProcessor
:
rabbitTemplate.convertAndSend(exchangeNameOut, message.getString(PERSISTENCE_MESSAGE_ROUTING_KEY),
message.getString(PERSISTENCE_MESSAGE_BODY),
m -> {
m.getMessageProperties().setCorrelationIdString(""+analyticRuntime.getId());
return m;
});
如果您不使用Java8,请使用new MessagePostProcessor() { ... }