28.17. 使用 JMSReplyTo 进行后回复
当使用 Camel 作为 JMS 侦听器时,它会设置 Exchange 属性,其值为 ReplyTo javax.jms.Destination
对象,其键为 ReplyTo
。您可以按照以下方法获取 此
目的:
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
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.");
// 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 属性中提供 回复
对象。然后,Camel 将提取此属性并将其用于实际目的地。然而,端点 URI 必须包含 dummy 目的地。例如: