Anypoint JMS Connector With Mulesoft
When you work with the Anypoint JMS Connector in Mulesoft, you can enable one-to-one communication, deliver messages to a variety of receivers, and more.
Join the DZone community and get the full member experience.
Join For FreeJMS (Java Messaging Service) is mostly used with APIs, enabling the application to communicate through the exchange of messages. JMS connector is capable of sending and receiving messages to and from topics and queues.
JMS supports two models for messaging:
Queue (point to point).
Topic (publish-subscribe).
Queue
It enables one-to-one communication. It is also called point-to-point communication.
The sender will deliver a message to the queue and single receivers will pick the message from the queue.
The receiver doesn't need to listen to queue at the time when the message is sent to the queue.
Topic
It enables one-to-many communication. It is also called publish-subscribe communication.
The publisher will deliver the message to a topic and it will be received by all subscribers who are actively listening to the topic.
A subscriber will miss the published message if it is not actively listening to the topic unless messages are made durable.
We will walk through how to use Anypoint JMS Connector for receiving and sending messages to a topic.
JMS Connector for Publishing Message to Topic
Place a JMS connector at the Message Source section in Mule Flow.
Configure the connector properties like Display Name and Topic and click Add Connector Configuration. This will open another window. Select the JMS of your choice. In this case, we will select ActiveMQ and press OK.
After clicking OK, it will open another window where you need to provide your Broker URL and username/password if applicable.
Now, you need to add the ActiveMQ JAR file in your project. Drag and Drop the jar file (i.e., activemq-all-5.6.0.jar
) into your project, go to the Package Explorer pane, and right click then select Build Path > Add to Build Path.
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="jmsconnectorFlow">
<jms:inbound-endpoint topic="test" connector-ref="Active_MQ" doc:name="JMS"/>
<logger level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="src/test/resources" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
This is how you can configure your JMS topic for publishing messages to ActiveMQ.
JMS Connector for Subscribing Message from Topic
Place the JMS connector at the middle or end of the flow (basically, in the Message Processor region).
Configure JMS Connector in the same way as we have done for Publishing the message to the topic. You need to add the Active MQ JAR file for subscribing the message to the topic, as has been explained above.
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="jmsconnectorFlow">
<file:inbound-endpoint path="src/test/resources" responseTimeout="10000" doc:name="File"/>
<logger level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint topic="test" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
</mule>
This is how you can configure your JMS Topic for subscribing message from ActiveMQ.
Supported JMS Providers
Out-of-box support for ActiveMQ, WebLogic JMS, Generic, or any custom JMS.
Hornet MQ, Open MQ, Solace JMS, Tibco EMS.
WebSphere MQ.
Now, you know how to subscribe and publish message to and from JMS topics!
Here is the video tutorial:
Opinions expressed by DZone contributors are their own.
Comments