How to Use JMS ActiveMQ With Mule 4: Part 1
In this blog, we will see what is JMS, why it is used, what different features are provided by JMS, and how we can install JMS ActiveMQ on our system.
Join the DZone community and get the full member experience.Join For Free
What is JMS?
JMS (Java Messaging System) is mostly used to enable the communication between APIs using an exchange of messages. It provides loosely coupled, reliable and asynchronous communication.
ActiveMQ is an open-source protocol developed by Apache which functions as an implementation of message-oriented middleware (MOM). Its basic function is to send messages between different applications.
A messaging system is composed of a JMS Broker (middleware), Queues and Topics, Producers, and Consumers.
JMS Broker is an application server that sits in between the sender (producer) and receiver (consumer). JMS Broker receives messages from producers and sends messages to consumers. It means that a Message sent from the Producer is not directly received by the consumer, instead, it is first received by the Broker and after receiving a message, the broker forwards the message to consumers.
JMS producer (sender) is an entity that creates and sends messages to JMS Queue or topic.
JMS consumer (receiver) is an entity that receives messages from the JMS queue or topic.
Using JMS we can send messages to queue or topic. Now let's understand what they are and why they are used.
Used for point to point OR 1 to 1 communication.
Used for one to many communication OR Pub-sub communication.
A message published to a queue can only be consumed by only one subscriber/receiver.
A message published to a topic can be consumed by any number of subscribers.
The receiver doesn’t need to listen to the queue at the time the message is sent.
A subscriber will miss the published message if it is not actively listening to the topic. (Unless the topic is made durable.)
Advantages of JMS
- Loosely Coupled
How to Setup JMS Active MQ (On Local)
- Download the ActiveMQ from the below link: https://activemq.apache.org/components/classic/download/
- After successful download, move it to the location where you want to keep ActiveMQ and Unzip it.
- After unzip, open the cmd and move to the path where you unzipped ActiveMQ then go to the bin folder.
- Run the command
activeMQ startto start ActiveMQ:
- Open the ActiveMQ console by going to the link: http://localhost:8161/admin/
- It will ask for a username and password. The default username is 'admin' and the password is 'admin'.
- On successful login, the JMS console would be shown like below.
- We can create a Queue by clicking on Queues. We need to Enter the name of the queue, that we want to create. Here we are giving the name of the queue as
- We can see that the queue named testQueue1 has been created in ActiveMQ.
- The creation of a topic in JMS is very easy. On the JMS console, we need to click on the topic.
- We need to write the name of the JMS topic which we want to create and then click on Create option.
- After clicking on create, we can see that testTopic1 is added to the topic list.
This is how we can create Queue and Topic from the JMS console. In the next part, we will see how we can use JMS ActiveMQ in Mulesoft.
Opinions expressed by DZone contributors are their own.