Request-reply messaging
JMS messaging with Camel (and in general) is asynchronous by default. Messages are
sent to a destination, and the client doesn’t wait for a reply. But there are times when
it’s useful to be able to wait and get a reply after sending to a destination. One obvious
application is when the JMS destination is a frontend to a service—in this case, a client
sending to the destination would be expecting a reply from the service.
JMS supports this type of messaging by providing a JMSReplyTo header, so that the
receiver knows where to send the reply,
and a JMSCorrelationID, used to match
replies to requests if there are multiple
replies awaiting. This flow of messages is
illustrated in figure 7.5.
Camel takes care of this style of messaging,
so you don’t have to create special
reply queues, correlate reply
messages, and the like. By changing the
message exchange pattern (MEP) to
InOut, Camel will enable request-reply
mode for JMS.
To demonstrate, let’s take a look at an order validation service within Rider Auto
Parts’ backend systems that checks orders against the company database to make sure
the parts listed are actual products. This service is exposed via a queue named validate.
The route exposing this service over JMS could be as simple as this:
from("jms:validate").bean(ValidatorBean.class);
When calling this service, you just need to tell Camel to use request-reply messaging by
setting the MEP to InOut. You can use the exchangePattern option to set this as follows:
from("jms:incomingOrders").to("jms:validate?exchangePattern=InOut")...
You can also specify the MEP using the inOut DSL method:
from("jms:incomingOrders").inOut().to("jms:validate")...
With the inOut method, you can even pass in an endpoint URI as an argument, which
shortens your route:
from("jms:incomingOrders").inOut("jms:validate")...
By specifying an InOut MEP, Camel will send the message to the validate queue and
wait for a reply on a temporary queue that it creates automatically. When the ValidatorBean
returns a result that message is propagated back to the temporary reply
queue, and the route continues on from there.
Rather than using temporary queues, you can also explicitly specify a reply queue.
This can be done by setting the JMSReplyTo header on the message or by using the
replyTo URI option described in table 7.5.
A handy way of calling an endpoint that can return a response is by using the
request methods of the ProducerTemplate. For example, you can send a message into
the incomingOrders queue and get a response back with the following call:
Object result = template.requestBody("jms:incomingOrders",
"<order name=\"motor\" amount=\"1\" customer=\"honda\"/>");
This will return the result of the ValidatorBean.
To try this out for yourself, go to the chapter7/jms directory in the book’s source,
and run this command:
mvn test -Dtest=RequestReplyJmsTest
The command will run a unit test demonstrating request-reply messaging as we’ve discussed
in this section.
In the JMS examples we’ve looked at so far, several data mappings have been happening
behind the scenes—mappings that are necessary to conform to the JMS specification.
Camel could be transporting any type of data, so that data needs to be
converted to a type that JMS supports. We’ll look into this next.
Request-reply messaging相关推荐
- golang nats request/reply模式
request端代码 request.go package mainimport ("github.com/nats-io/nats.go""log"" ...
- 网关状态检测 echo request/reply
计算机中的IP地址和子网掩码的关系:标识该计算机所在的网络号.子网号以及主机号,当访问某个ip时,首先将此ip与本地子网掩码进行"与"运算,判断是否与本机ip和本机子网掩码&quo ...
- babyos2(39) network(5) -- icmp echo request, reply, receive
前面为babyos2 实现了发送IP数据报,但只测试了同一个局域网内发送,而当目的IP跟发送发自己的IP不在同一局域网内时,babyos2会把IP数据报发往网关.而如何测试是否发送成功,首先想到的是p ...
- 深入理解DefaultMessageListenerContainer
http://blog.csdn.net/zhaozhenzuo/article/details/7934881 DefaultMessageListenerContainer是一个用于异步消息监听的 ...
- 基于JMS规范的ActiveMQ
为什么80%的码农都做不了架构师?>>> 基于JMS规范的ActiveMQ JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台 ...
- Cloud Native Computing Foundation Welcomes the NATS Messaging Protocol into the Fold
2019独角兽企业重金招聘Python工程师标准>>> Continuing to fill out its portfolio of cloud-friendly infrastr ...
- 我的WCF之旅 (11): 再谈WCF的双向通讯-基于Http的双向通讯 V.S. 基于TCP的双向通讯...
在一个基于面向服务的分布式环境中,借助一个标准的.平台无关的Communication Infrastructure,各个Service通过SOAP Message实现相互之间的交互.这个交互的过程实 ...
- Ethernet/IP 学习笔记六
Ethernet/IP 学习笔记六 EtherNet/IP defines two primary types of communications: explicit and implicit (Ta ...
- 我的WCF之旅(13):创建基于MSMQ的Responsive Service
一.One-way MEP V.S. Responsible Service 我们知道MSMQ天生就具有异步的特性,它只能以One-way的MEP(Message Exchange Pattern)进 ...
- python消息中间件有哪些_消息中间件选型
一. 分布式系统消息通信技术简介 分布式系统消息通信技术主要包括以下几种: 1.RPC(Remote Procedure Call Protocol). 一般是C/S方式,同步的,跨语言跨平台 ...
最新文章
- 得到弹出菜单QMenu的高度
- python要学哪些_学python都要学哪些内容?
- 求解最大字段和的几种方法
- XMLHTTP中setRequestHeader参数问题
- 雪珊教你学计算机,我日了数学老师
- 简单数据分布分析及python实现
- 免费持久的天气预报web service
- linux查看php命令目录权限,PHP执行linux命令mkdir权限问题
- 【Java】5 个刁钻的 String 面试题
- ubuntu 20.04双系统安装_win10上跑Ubuntu不用虚拟机不用双系统!
- 商标注册流程与注意事项 logo 商标注册类型分类解释
- 一千个哈姆雷特,一千个手游开发者
- HTML5与HTML4区别
- LeetCode之验证二叉搜索树
- Steve Pavlina:如何ASAP找到人生目标?
- js使用百度离线地图
- Linux文件打包与压缩
- css选择器权重排序_css选择器的权重计算
- mysql column specified twice_Column 'box_id' specified twice 错误
- VMware vCenter Server远程代码执行漏洞复现 CVE-2021-21972
热门文章
- HarmonyOS之数据管理·轻量级偏好数据库的应用
- LeetCode Algorithm 19. 删除链表的倒数第 N 个结点
- 145. Binary Tree Postorder Traversal 二叉树的后序遍历
- 数据库开发——MySQL——基本操作
- 《信息学奥赛一本通》高精除以高精,求它们的商和余数。
- 使用Redis 实现消息队列
- 【Linux系统编程】进程间通信概述
- oracle高级复制管理里面,配置高级复制问题,请大家指点!
- php作品答辩问问题,一般答辩会问到什么问题
- 51nod 1268 和为K的组合 dfs