Using JMS Endpoint for ActiveMQ in Mule ESB application

I showed you all how to configure JMS Endpoint in the previous tutorial. In this tutorial, I will do an example of using JMS Endpoint for ActiveMQ in the Mule ESB application to see how it works.

So what is our problem?

Suppose, we have a system with many applications and there is an application A needs to send a message to other applications via HTTP protocol.

Prior to the concept of ESB, in order to solve this problem, we would typically create services in other applications to receive the message from application A. And so, application A could pass the message to other applications directly and easily.

But with this approach, application A will have to call multiple times through the services of those applications to transmit the same message. Imagine, what is the problem if the number of applications increases? We need to modify the code of application A to meet our needs.

The ESB approach helps us to solve this difficult problem. Other applications will now listen to a Queue or a Topic of a JMS server managed by the ESB, the ESB will receive a message from application A via the HTTP protocol and then it will convert the HTTP message to in the form of JMS message and sent to the Queue or Topic that other applications are listening to.

This solution will allow our system to be easily editable without having to re-edit the running system.

OK, the theory is so. How will we implement this Mule ESB application? Let’s go in details!

– First, I will create a Mule project named ESBExample using Anypoint Studio.

Using JMS Endpoint for ActiveMQ in Mule ESB application

If you do not know how to create a Mule ESB project, you can refer to this tutorial.

– Next, we will implement the receiving message request from application A for the Mule ESB application.

Mule ESB has a connector as HTTP Connector to implement a service that allows the Mule ESB application can receive HTTP requests from other applications.

Now, looking for the HTTP Connector in the Mule Palette toolbar:

Using JMS Endpoint for ActiveMQ in Mule ESB application

then drag and drop it into Anypoint Studio Editor:

Using JMS Endpoint for ActiveMQ in Mule ESB application

To configure the HTTP Listener Connector, please refer to this tutorial.

Here, I configured it as follows:

Using JMS Endpoint for ActiveMQ in Mule ESB application

Global HTTP Listener Configuration

Using JMS Endpoint for ActiveMQ in Mule ESB application

– After receiving the request from application A, we will use a Mule ESB Transformer called “Byte Array to String” to convert the HTTP body request data into String.

To do this, in the Mule Palette, find Transformer “Byte Array to String”.

Using JMS Endpoint for ActiveMQ in Mule ESB application

then drag and drop it into the Process section of Anypoint Studio Editor.

Using JMS Endpoint for ActiveMQ in Mule ESB application

With this transformer, we do not need to configure anything.

– Now, we will go to the last part of adding a JMS Endpoint to send a String request to a Topic of the ActiveMQ server.

Look for the JMS Endpoint in the Mule Palette,

Using JMS Endpoint for ActiveMQ in Mule ESB application

then drag and drop it into Editor’s Process after Transformer “Byte Array To String”:

Using JMS Endpoint for ActiveMQ in Mule ESB application

To configure JMS Endpoint, please refer to this tutorial!

Here, I configured as follows:

Using JMS Endpoint for ActiveMQ in Mule ESB application

Global JMS Endpoint for ActiveMQ:

Using JMS Endpoint for ActiveMQ in Mule ESB application

In this step, we need to add ActiveMQ dependency to our Mule ESB application.

Please open the pom.xml file in our project to add this dependency.

– The last step is: we need to run an ActiveMQ server so that our Mule ESB application can connect and send the message.

If you do not know how to install and add a Topic in ActiveMQ server, you can refer to the following tutorials:

Install Apache ActiveMQ

Add new Topic in ActiveMQ

Here, I added a new Topic named “test”:

Using JMS Endpoint for ActiveMQ in Mule ESB application

OK, so everything is finished, now let run your Mule ESB application in Anypoint Studio to test and check the result!

To run the Mule ESB application in Anypoint Studio, right-click on the project and select Run As …, then select Mule Application with Maven.

Result:

Using JMS Endpoint for ActiveMQ in Mule ESB application

To test, you use a REST Client to send an HTTP request to our Mule ESB application and check the result in Topic in the ActiveMQ server.

For example, I’m going to send to a Mule ESB application with an address:

http://localhost:8081/esb/test

with the content “Hello Mule ESB” as below:

Using JMS Endpoint for ActiveMQ in Mule ESB application

And this is the result in the ActiveMQ server:

Using JMS Endpoint for ActiveMQ in Mule ESB application

Logging message:

Add Comment