How to Install RabbitMQ Using Docker

In this article, I will show how you can install RabbitMQ in AWS using Docker, which can help you to build microservices for your application. Before that let’s discuss RabbitMQ and Docker.

What is RabbitMQ

According to Wiki, RabbitMQ is open-source message-broker software that originally implemented the Advanced Message Queuing Protocol and has since been extended with a plug-in architecture to support Streaming Text Oriented Messaging Protocol, MQ Telemetry Transport, and other protocols.

So RabbitMQ is a message broker where it saves messages in a Queue and then pushes those messages to the corresponding consumer. You can use RabbitMQ in your application to make it highly scalable and fully reliable. There are situations where we need to do a lot of things and we don’t want to be surprised if our script suddenly stops due to timeout or lack of memory issue. One example can be sending multiple emails in a batch process. Let’s assume you want to send 5000 emails to your mailing list, now if you try to send out via a single script then there is a high chance is that it may go wrong in the middle of the process. To avoid this kind of issue, we introduce message queuing, where each email is queued in RabbitMQ and then process one by one using a consumer. In this process, there is no risk of script timeout or lack of memory shortage and the whole process finishes with exact confirmation of accomplishment.

As we know about RabbitMQ, let’s learn about Docker. Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

So actually docker lets us run RabbitMQ on any platform we want. It makes the whole process so easy that, even on your local machine you can use docker to run RabbitMQ, and similarly in the production environment, you can use Docker to run RabbitMQ. Next, we will discuss how to do that.

How to Install

RabbitMQ is the most widely deployed open-source message broker. In the below section, I will describe how easily you can install and run RabbitMQ using Docker.

At first, we need to create an EC2 instance and then connect to it via Putty or Terminal.

After that, we need to install the docker using following command.

sudo yum install docker -y 

Start the docker service by running this command

sudo systemctl start docker

Then pull RabbitMQ image to your local by running the following command.

sudo docker pull rabbitmq

Then run this command to run the RabbitMQ

sudo docker run -d --hostname atiq --name rabbit-server -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=abcd123454526ewe5 -p 5672:5672 -p 15672:15672 rabbitmq:3-management

Afer that, open a new tab in browser and visit to this url

http://{ip}:15672

A video tutorial of this example is published here, so that you exactly follow what I did here and setup without any error.

Conclusion

In conclusion, I would say that docker is a nice platform to build and run your application anywhere. We will use Docker here to install RabbitMQ so that you can make scalable applications easily.

Checkout my other tutorial on docker here

Leave a Comment

Your email address will not be published.