使用 producerTemplate 获取 JMSMessageID

get JMSMessageID when use producerTemplate

在骆驼中,

ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate();
producerTemplate.sendBody("endpointqueue?includeSentJMSMessageID=true", ExchangePattern.InOnly, body);

我需要获取从 IBM MQ/ActiveMQ 返回的 JMSMessageID。我正在调试模式下查看交换值,但找不到它。我只能找到sessionID。它存储在哪里以及如何获取?

Camel documentation 说:

includeSentJMSMessageID - only applicable when sending to jms destination using InOnly. enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

includeSentJMSMessageID 是否与我的需求不同,还是我遗漏了什么?

文档说 JMS MessageID 可用 header。 所以你应该可以 return 像这样:

from("direct:queueMessage")
    .to("jms://myqueue?includeSentJMSMessageID=true")
    .setBody().simple("${header.JMSMessageID}");

然后使用以下方式发送消息:

String msgId = producerTemplate.requestBody("direct:queueMessage", body, String.class);