java - How to handle response timeout in activeMq when using two queues for communication between two applications
问题描述
Say you have an Application A and an Application B that communicates together using ActiveMQ queues. The communication happens as below.
- A sends a request message to application B using the queue name com.example.requestQueue
- B consumes the message request from the queue name com.example.requestQueue
- B takes some time to handle the message request and then sends a response back to B using the response queue name com.example.responseQueue
- A consumes the response message from com.example.responseQueue queue and is done
If application B is always answering, there is no problem. But if for some reason the application B consumes a message from the request queue com.example.requestQueue and never puts a response message in the response queue com.example.responseQueue, application A will wait forever. Is there any way to solve this kind of problem please?
NB: The application A is written with Java and Camel and the application B is Written in C++
Thanks.
解决方案
Camel supports request-reply flows in a single route (exchange pattern InOut), or you can break the request-reply into two separate routes (both exchange pattern InOnly) depending on your use case.
The request-reply patterns have timeout settings available based on the Camel component used. Add the timeout to the Application A Camel route request-reply.
ref: SJMS Component - Newer JMS component
ref: JMS Component - Original JMS component
ref: Request Reply pattern - Info on InOut patterns
Side note-- If Application A is also expected to return something to a caller (ie a web app or a REST/SOAP client), than you would want to make sure you set the messaging response timeout to be lower than than the timeout used by the caller. This allows Application A to return a proper exception/error to the caller before the caller's timeout occurs.
推荐阅读
- c# - 优化 linq 查询的更好方法
- php - 如何检查 foreach 循环中值为 1 的值
- reactjs - React Native 尝试为文本创建边框
- javascript - 是否可以添加 props.children 的 ref 没有 ref
- database - 在 hive 和 impala 中使用不同的分隔符创建表
- vue.js - 如何测试包装在 3rd 方组件中的代码
- typo3 - listAction() 的作用是什么?
- c# - 无效的网址在我的网站中显示为空白页面
- python - 读回保存的 LGBMClassifier 模型
- linux - KDE (KIO) 下 TransferJob 的 HTTP 错误代码