51.18. 使用 JMSReplyTo 进行更新的回复
当使用 Camel 作为 JMS 侦听器时,它会设置一个 Exchange 属性,其值为 ReplyTo javax.jms.Destination
对象,其键为 ReplyTo
。您可以按如下方式 获取
此目标:
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
然后,稍后使用它来使用常规 JMS 或 Camel 发送回复。
// we need to pass in the JMS component, and in this sample we use ActiveMQ JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent); // now we have the endpoint we can use regular Camel API to send a message to it template.sendBody(endpoint, "Here is the late reply.");
发送回复的不同解决方案是在发送时在同一 Exchange 属性中提供 replyDestination
对象。然后 Camel 将获取此属性并将其用于实际目的地。端点 URI 必须包含一个 dummy 目的地。例如:
// we pretend to send it to some non existing dummy queue template.send("activemq:queue:dummy, new Processor() { public void process(Exchange exchange) throws Exception { // and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination); exchange.getIn().setBody("Here is the late reply."); } }