Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Anypoint JMS Connector With Mulesoft

DZone's Guide to

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.

· Integration Zone
Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90-day trial of 3Scale by Red Hat

JMS (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:

  1. Queue (point to point).

  2. 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.

Image titleAfter clicking OK, it will open another window where you need to provide your Broker URL and username/password if applicable.

Image title

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.

Image title

Image title

<?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.

Image title

<?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:


Explore the core elements of owning an API strategy and best practices for effective API programs. Download the API Owner's Manual, brought to you by 3Scale by Red Hat

Topics:
mulesoft ,anypoint ,jms connector ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}