Java Messaging Service is often used for asynchronous communication between client and server. Mule ESB allows JMS for synchronous communication wherein the client and server can be be completely decoupled. The JMS synchronous communication is also referred to as “JMS Back-channel”. The JMS back-channel is usually not provided by the JMS protocol or any JMS brokers and has to be implemented by the applications. In this blog, a simple use case of the synchronous JMS communication using Mule ESB and Active MQ is described.
In the below example, a string message is sent and received in order to demonstrate JMS back-channel. The Active MQ is used as a message broker for the demo. The JMS back-channel can be implemented by Mule ESB in two ways which are described in the following sections.
This will invoke the “jmsmessagepublisher” flow and will send a message to request queue.
“Jmsmessagereceiver” queue will log the request message received and return a new message.
“Jmsmessagepublisher” flow will receive the message returned from the “Jmsmessagereceiver” queue and will log the final response.
The final response will be printed on the browser.
If using approach 1 and running in INFO mode, the temporary queue and correlation id are saved in logs.
Approach 1 vs Approach 2
Approach 1 is useful, if message has to be sent and received on the same queue whereas Approach 2 is useful if there are two different queues for sending and receiving messages.
Approach 1 creates a temporary queue for synchronous communication between client and server whereas approach 2 uses two named queues.
Approach 1 creates and destroys the temporary queue for every message exchange and hence consumes additional CPU cycles and memory compared to approach 2.
Approach 1 can raise a concern on performance and resource utilization.
JMS synchronous communication has an advantage of complete decoupling between the client and service. As described in this blog, the above mentioned approaches for JMS synchronous messaging using Mule ESB has their own set of advantages and disadvantages.
The implementation approach can be chosen on the basis of use case for the project.
If you would like to find out more about how Systems Integration could help you make the most out of your current infrastructure while enabling you to open your digital horizons, do give us a call at +44 (0)203 475 7980 or email us at Salesforce@coforge.com