From the technical center of excellence of Massil Technologies, our technology leader Srini makes it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog addresses the five steps involved in queuing in Mule ESB using RabbitMQ. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.
What is RabbitMQ?
As per the definition published at https://www.rabbitmq.com/, RabbitMQ is the most widely deployed open source message broker. With more than 35,000 production deployments of RabbitMQ world-wide at start-ups and large enterprises, RabbitMQ is the most popular open source message broker. RabbitMQ is lightweight and easy to deploy on-premises and in the cloud. It supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements. RabbitMQ runs on many operating systems and cloud environments and provides a wide range of developer tools for most popular languages.
Installation of RabbitMQ:
To install Rabbit MQ you need to install Erlang in your system for download and install erlang go to https://www.erlang.org/downloads
Download the appropriate version for your system and install it.
Download the RabbitMQ into your system. To download RabbitMQ go to https://www.rabbitmq.com/download.html
Install RabbitMQ. Its default Port is “15672” but by installing you won’t be able to access it.To enable the port you have to install certain plugins as explained in Step2.
By running above command, it will enable plugins like ampq_clinet and cowlib so on.
In your browser open the new window and go to ‘loalhost:15672’.It is default port for RabbitMQ.
It will ask you to enter username and password. For the new user who doesn’t have any credentials to login into the server. Try these default credentials username: “guest”, Password: “guest”. Now you will get into the admin portal.
Go to queue tab and Create a queue.
Give a name for the queue and hit add queue button then the queue will be created.
Steps in AnyPoint Studio:
Create a new project.
Check whether you have AMQP connector in your palette or not.
Click the indicated option in the image, it will take you into exchange
Alternatively, you can find this in the >Help > install new software > Any point Connectors Update Site -https://repository.mulesoft.org/connectors/releases/3.5.0
Drag an HTTP connector from palette and configure it
Connect an AMQP connector to the HTTP and configure it like > General Settings >> Address attribute >>>give a proper queue name in the field of queue name.
Go to General Settings >> Property Attribute, the select checkbox called queue durable.
Go to Advance Settings >> Exchange Pattern >> Make as a one-way (Default)
^ connection Reference
Create a new connection by clicking the ‘+’ symbol
Go to Reference Settings >> Connection Reference >>>Protocol, and check the details
Save the settings made.
Add a payload to at the end of flow to run the project.
Send a message using postman to the project.
So far, we have seen how a message can be published, we now will see how to subscribe for it.
Subscribing to a message:
Take a new flow of the project.
Take an AMPQ connector and configure same as shown previously. Add acknowledge component to acknowledge the received message.
To store the message, take a file connector and give a path to it.
Run the project and send the message through postman. you can see the message will be stored in the given path.
Test your project using postman.
In the project, the first flow will be to publish the message. Second flow will be to subscribe for it. File connector will save the message in the file path you gave.
You can see the graph which will show you how many messages are published how many clients received the message.
Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to firstname.lastname@example.org.