首页 > 解决方案 > 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.

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.

标签: javaspringapache-camelactivemq

解决方案


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.


推荐阅读