 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.
 <jms:activemq-connector name="Active_MQ"
username="username" password="password"
brokerURL="tcp://localhost:63636"
validateConnections="true" doc:name="Active
MQ" />
 Client Flow
 <flow name="jmsmessagepublisher"
doc:name="jmsmessagepublisher"><http:inbound-
endpoint exchange-pattern="request-response"
host="localhost" port="1111" path="backchannel"
doc:name="HTTP" /><set-payload value="Hello
World from Sender" doc:name="Set Payload"
/><response><logger message="Final Response:
#[payload]" level="INFO" doc:name="Logger"
/></response><logger message="Sending Message:
#[payload]" level="INFO" doc:name="Logger"
/><jms:outbound-endpoint exchange-
pattern="request-response" queue="myQueue"
connector-ref="Active_MQ" doc:name="JMS"
/></flow>
 <flow name="jmsmessagereceiver"
doc:name="jmsmessagereceiver"><jms:inbound
-endpoint queue="myQueue" connector-
ref="Active_MQ" doc:name="JMS" exchange-
pattern="request-response"/><logger
message="Received Message: #[payload]"
level="INFO" doc:name="Logger"/><set-payload
value="Hello World from Receiver"
doc:name="Set Payload"/><logger
message="New Message Back to Sender:
#[payload]" level="INFO"
doc:name="Logger"/></flow>
 A temporary response queue for JMS backchannel
is created internally using Request-response JMS
endpoints.
 Response is sent to the client via a temporary
queue.
 The response queue is anonymous and Mule
automatically sets the JMS_REPLY_TO property.
This property instructs Mule on where the reply
message needs to be sent.
 The response queue is created for every message
exchange and is destroyed immediately after the
client receives the response.
 JMSCorrelationId ensures proper sequencing.
 Open a browser and type the below URL
 http://localhost:1111/backchannel
 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.

Synchronous communication using jms back channel

  • 2.
     Java MessagingService 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.
  • 3.
     In thebelow 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.  <jms:activemq-connector name="Active_MQ" username="username" password="password" brokerURL="tcp://localhost:63636" validateConnections="true" doc:name="Active MQ" />
  • 5.
  • 6.
     <flow name="jmsmessagepublisher" doc:name="jmsmessagepublisher"><http:inbound- endpointexchange-pattern="request-response" host="localhost" port="1111" path="backchannel" doc:name="HTTP" /><set-payload value="Hello World from Sender" doc:name="Set Payload" /><response><logger message="Final Response: #[payload]" level="INFO" doc:name="Logger" /></response><logger message="Sending Message: #[payload]" level="INFO" doc:name="Logger" /><jms:outbound-endpoint exchange- pattern="request-response" queue="myQueue" connector-ref="Active_MQ" doc:name="JMS" /></flow>
  • 8.
     <flow name="jmsmessagereceiver" doc:name="jmsmessagereceiver"><jms:inbound -endpointqueue="myQueue" connector- ref="Active_MQ" doc:name="JMS" exchange- pattern="request-response"/><logger message="Received Message: #[payload]" level="INFO" doc:name="Logger"/><set-payload value="Hello World from Receiver" doc:name="Set Payload"/><logger message="New Message Back to Sender: #[payload]" level="INFO" doc:name="Logger"/></flow>
  • 9.
     A temporaryresponse queue for JMS backchannel is created internally using Request-response JMS endpoints.  Response is sent to the client via a temporary queue.  The response queue is anonymous and Mule automatically sets the JMS_REPLY_TO property. This property instructs Mule on where the reply message needs to be sent.  The response queue is created for every message exchange and is destroyed immediately after the client receives the response.  JMSCorrelationId ensures proper sequencing.
  • 11.
     Open abrowser and type the below URL  http://localhost:1111/backchannel  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.