搜索

51.18. 使用 JMSReplyTo 进行更新的回复

download PDF

当使用 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.");
    }
}
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.