About the JMS Connector:

The JMS connector enables the application to exchange messages using the JMS implementation of our own choice. Its main features include:

  • Pub/Sub pattern support on any given destination.
  • Listen/Reply pattern support on any given destination.
  • Publish-Consume pattern support on any given destination, with a fixed or temporary reply Queue.
  • Fully compliant with JMS 2.0, 1.1, and 1.0.2 specifications.

Mule 4 Example: Connecting To ActiveMQ Configuration:

<jms:config name="JMS_Config" doc:name="JMS Config" doc:id="bda7c128-ed6b-4fab-bdfc-0c63148fb16d" >
		<jms:active-mq-connection username="XXXXX" password="XXXXX" >
			<jms:factory-configuration brokerUrl="tcp://localhost:61616" />
		</jms:active-mq-connection>
	</jms:config>


Below are listed JMS Operations in Mule – 4:

Mule - 4 JMS Publish & Subscribe with Transformation

XTIVIA Blog CTA MuleSoftUse Case:

Publishing the source message into JMS-Queue and it will consume by an end system. In this scenario, I am publishing & consuming the JSON message from Queue, then converting it into XML format.

 

Mule Flow:

Step -1 :

Configure the HTTP Listener by giving hostname, port number, and path, along with this specify allowed methods (Optional) at the Advanced tab of HTTP connector.

Step-2:

Drag & Drop the Logger component to log the inbound message.

Step-3:

Configure publish operation of the JMS connector from the Mule palette window. And add connector-required libraries with connection details like the ones below.

And specify the Queue name to publish the message.

Step-4:

As in Step–3, configure the consume operation of the JMS connector from the Mule palette window.

And specify the consuming Queue name to read the message.

Step-5:

Drag & Drop the Transform Message component from the Mule palette window.

Mule - 4 JMS Publish & Subscribe with Transformation

From the above screen, SampleData defines the root tag of XML message as a result.

Step-6:

Drag & Drop the Logger component to log the result XML message.

Final Mule Flow:

Mule - 4 JMS Publish & Subscribe with Transformation

Final Config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce" xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="4862f344-02c0-4d4d-89f7-2572698011f2" >
		<http:listener-connection host="0.0.0.0" port="8084" />
	</http:listener-config>
		<jms:config name="JMS_Config" doc:name="JMS Config" doc:id="cbf14d84-19d6-4a3d-a288-dde77d6f2a75" >
		<jms:active-mq-connection username="admin" password="admin">
			<jms:caching-strategy >
				<jms:default-caching />
			</jms:caching-strategy>
			<jms:factory-configuration brokerUrl="tcp://localhost:61616" />
		</jms:active-mq-connection>
		<jms:consumer-config >
			<jms:consumer-type >
				<jms:queue-consumer />
			</jms:consumer-type>
		</jms:consumer-config>
	</jms:config>
	<flow name="MQ-PUB_SUB" doc:id="1cc1d138-1ead-4098-86ac-5f9cb6c74c96">
		<http:listener doc:name="Listener" doc:id="bbd9a567-6729-407f-b77a-71a33fd8bffb" config-ref="HTTP_Listener_config" path="mq" allowedMethods="POST">
		</http:listener>
		<logger level="INFO" doc:name="Logger" doc:id="e119c173-d4da-4c98-8823-a3a159286b5b" message="#[message.payload]"/>
		<jms:publish doc:name="Publish" doc:id="38c403b2-3b92-4924-86ee-e9efff43a8cb" config-ref="JMS_Config" destination="test"/>
		<jms:consume doc:name="Consume" doc:id="cbf84a03-9123-4ff1-ae2e-fd98f265c7cb" config-ref="JMS_Config" destination="test">
		</jms:consume>
		<ee:transform doc:name="Transform Message" doc:id="0dbd6d88-8254-452e-a308-7516b677449e">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/xml
---
SampleData : payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" doc:id="590d01e3-122d-42db-89b4-3845dd45eb3a" message="XML Data -----> #[message.payload]"/>
	</flow>
	
</mule>

Input & Output:

Mule - 4 JMS Publish & Subscribe with Transformation

XTIVIA Blog CTA MuleSoft

H@ppy Le@rning!

Are you still having trouble? Visit our MuleSoft blog. Our MuleSoft Anypoint experts can help you get past any issues you are currently experiencing, complete the project for you, or help with anything in between. As a MuleSoft partner, contact us to speak with one of our MuleSoft experts now!