This blog post will explain what JMS is and why it’s used. It will describe some of its features. It will guide you on how to install JMS ActiveMQ on our system. It will also show you how to utilize JMS with Mulesoft. We will examine the ways in which we may execute various JMS operations on Queue using the Mulesoft JMS connector.
JMS: What is it?
The primary purpose of JMS (Java Messaging System) is to provide message-based communication across APIs. It offers dependable, asynchronous, loosely connected communication.
An open-source protocol called ActiveMQ was created by Apache to serve as a message-oriented middleware (MOM) implementation. Sending messages across several apps is its primary use.
A JMS Broker (middleware), Queues and Topics, Producers, and Consumers make up a messaging system.
A JMS Broker is an application server that acts as a middleman between a producer and a consumer. JMS Broker transmits messages to customers after receiving messages from producers. In other words, the Producer does not send a message directly to the Consumer. The Broker receives the message first and then transmits it to the Consumer.
Messages are created and sent to JMS Queues or topics by JMS producers, also known as senders.
Messages from the JMS queue or topic are received by an entity known as a JMS consumer (receiver).
Sending messages to a queue or topic is possible using JMS. Let’s now explore their definitions and applications.
Queue
A queue is used for one-to-one or point-to-point communication. A single subscriber or recipient is limited to consuming a message that is published to a queue. When the message is transmitted, the recipient is not required to listen to the queue.
Topic
used in one-to-many or pub-sub interactions. Every subscriber has access to a message posted to a topic. The published message will be missed by a subscriber who is not actively monitoring the issue. (Unless resilience is built into the subject.)
Benefits of JMS
- Loosely Coupled
- Asynchronous
- Reliable
- Scalability
How to Configure Active MQ in JMS (On Local)
- Get the ActiveMQ by clicking the following link:
- <u>ActiveMQ (apache.org)</u>
- After a successful download, unzip it and move it to the area you wish to keep ActiveMQ.
- Open the CMD window after unzipping ActiveMQ, navigate to the bin folder, and then press enter.
- To start ActiveMQ, type the following command:
activeMQ start

- Visit the following URL to launch the ActiveMQ console: <u>http://localhost:8161/admin/</u>
- It will request a password and username. ‘Admin’ is the default password and login name.

- Following a successful login, the JMS console would appear as follows.

- By selecting Queues, we are able to build a queue. The name of the queue that we wish to create must be entered. The queue is referred to as testQueue1 in this instance.

- It is evident that the testQueue1 queue has been established in ActiveMQ.

- In JMS, creating a topic is really simple. We must click on the topic on the JMS console.

- After writing the name of the JMS topic we wish to create, we must select the Create option.

- We can observe that testTopic1 has been added to the subject list after clicking on create.
How to Utilize Mulesoft’s JMS
Our program can use the JMS implementation for messaging thanks to Anypoint Connector for JMS (JMS Connector). Among its primary characteristics are
- Pub/Sub pattern compatibility at any location.
- On any destination, listen/respond pattern support is available.
- With a fixed or temporary reply queue, publish-consume patterns can be supported on any given destination.
Operations Provided via JMS Connector
- To publish messages into a JMS, use the publish command.
- Consume: utilized to take in the published message delivered by Queue.
- Listening for incoming messages is possible with the JMS Subscriber for Destinations on New Message.
- Publish Consume: Send a message to a JMS destination. Wait for a response either to the specified ReplyTo destination. Alternatively, the response can go to a temporary destination that is established dynamically.
- While consuming the message, if the AckMode#MANUAL mode is selected, Ack is utilized to perform an ACK.
- When consuming the message, and the AckMode#MANUAL mode is selected, use the recover session function. It is used to carry out a session recovery.
Publish
As seen in the graphic below, we will design a straightforward flow. Here, we’re using an HTTP listener. We perform a JMS Publish operation to publish the message into the JMS queue (testQueue1). A logger prints the message’s publication to ActiveMQ.

The configuration must be completed before dragging and dropping the JMS connector from the menu. The JMS connector configuration window will open when we click the plus (+) icon for this.

First, we must add the JMS-required libraries to the setup. To do this, select the Configure button that appears next to each dependency. then choose Include suggested libraries.

Information about the library will be displayed in a pop-up window. This window will appear when you select the Add suggested libraries option. We’ll press the OK button.

The Green Tick icon next to the library name indicates success. The necessary library has been added for the JMS ActiveMQ Client. This can be verified once the pop-up has closed.

We’ll include an ActiveMQ Broker dependency in a similar manner. We can observe that ActiveMQ Broker and ActiveMQ KahaBD are optional dependencies in the above graphic.
We will provide the login credentials, broker URL, and password as soon as these libraries are added. Since we are using localhost for this demo, the broker url is tcp://localhost:61616, and the username and password are admin.

We will attempt to test the connection once we have added all necessary values to the configuration. We will receive the following message, “Test Connection Successful,” if everything is configured correctly.
Note: While attempting to establish a connection, ActiveMQ would be operational.

Consume
When a Mule flow is in progress, consume is used to choose or receive messages from the JMS queue.

The image above displays the JMS consume operation configuration. Here, we are supplying the Destination. This is the name of the queue from which we wish to send or receive messages. We are also providing the content type of the messages that need to be read.
On New Message
A Listener/Source component called the On New Message update is used to retrieve the published message from the JMS.
This component picks up newly published messages as soon as they are published, actively listening to the JMS destination (Queue/Topic).

Note: Any On-New Message component will consume the message. This occurs if several On-New Message components point to the same queue.
]]>