A Primer on RabbitMQ, the Popular Open Source Message Broker


RabbitMQ is the most popular and widely deployed message broker and it happens to be open source. Its versatility makes it easily deployable in the cloud and in situ. It supports high availability and multiple messaging protocols.

RabbitMQ is a message broker, i.e., software that manages and defines message queues. It is a queue manager that connects applications and transmits messages through them. A message can be data or information like a simple text message, or some important details about a task that should be initiated on some other application. Message queuing software stores all the messages until the destination system connects and takes the message out of the queue. The destination application then transmits the message in the proper manner.

The basic architecture of RabbitMQ has three main components.

  • Producers – client applications that create messages and send them to the broker/message queue.
  • Consumers – connect to the queue and subscribe to the message that needs to be processed.
  • Broker – a middleman who keeps messages in queue until the consumers take them.

Any software can be a producer, a consumer or both together. A message broker is used to reduce loads and hasten the delivery time of tasks. Tasks that normally take longer to process are forwarded to a third party to perform this job. This is faster as the only job for the third party is to process the task sent to it.

Figure 1: The basic structure of RabbitMQ

When to use RabbitMQ

Let’s look at an example to understand this better. There is a website that allows users to upload information, generates a PDF containing this information and emails this PDF back to the user. The tasks that take time involve handling of the data, making a PDF from the data and sending an email with the PDF attachment. This time can be minimised using a message queue (RabbitMQ).

Once the user has entered all the details, the application creates a new task called ‘PDF processing’ and puts in all the information, including the email address. This message is queued as defined by the broker, which will route this message to the right queue for the PDF creation task. The consumer then consumes this message, generates a PDF, and sends an email attaching the same PDF on behalf of the application.

Message queueing enables servers to perform tasks quickly. It balances the load between different workers when the message needs to be distributed to multiple recipients.

Once the producer puts in all the information, the consumer can retrieve the message from the queue and start generating the PDF at the same time as the producer is piling up the same queue with new messages. Here the consumer can be a server rather than a producer, or both can be at the same server. This task is independent of the languages used. So requests can be created in one language and handled in another. Both applications will communicate only through loosely coupled messages.

Producer messages are not directly published to queues. They are sent to an exchange, which decides the best route for them. The exchange routes the message to the proper consumer with the help of routing keys and bindings. A binding is nothing but a key between the queue and the exchange.

Figure 2: RabbitMQ message flow

RabbitMQ features

From startups to large enterprises, RabbitMQ is the most widely used and deployed open source message broker. Its features are listed below:

  • Asynchronous messaging
  • Routes messages using typical routing logic
  • Provides delivery acknowledgement
  • Programming language support
  • Supports any programming language you can think of

Distributed deployment

Various RabbitMQ servers working on a local network can be clustered together to provide high availability and output for multiple zones because of the following reasons:

  • RabbitMQ is easy to deploy in clouds
  • Comes with pluggable authentication, and is also quick and easy to deploy in private or public clouds
  • Has a very simple management UI, which makes monitoring and managing message queues a lot easier
  • Quick integration
  • Comes with various tools and plug-ins, which extend their functionalities and integrate with different systems. You can also develop your own plug-in and integrate it with RabbitMQ
  • Supports messaging over multiple protocols
  • Message tracing is possible with RabbitMQ
  • If something goes wrong with the messaging system, RabbitMQ allows you to trace it back to find the bug
Figure 3: RabbitMQ Instance Setup -1

Important RabbitMQ terms and concepts

Table 1 lists some important terms and concepts to help us understand RabbitMQ better.Setting up a RabbitMQ instance

Setting up a RabbitMQ instance is as easy as pie. The steps that need to be followed are listed below.

  • To create a RabbitMQ instance, you need to sign up on the URL https://customer.cloudamqp.com/instance/create.
  • Select your plan and give a proper name to your instance. In this case, I have selected a free instance, which is Little Lemur (Figure 3).
  • Select the region where you want to deploy your instance as shown in (Figure 4).
  • On confirming the details, the instance will be created with the specified name and tags (Figure 5).
  • Once the instance is up, you can manage it and create queues using the RabbitMQ Manager (Figure 6).

    Figure 4: RabbitMQ Instance Setup-2
Figure 5: RabbitMQ Instance Setup – 3
Figure 6: RabbitMQ Manager

You can now create an application using any programming language like Ruby, Java, Node.js, JavaScript, Python, PHP, C#, etc, and start communicating with the RabbitMQ message broker through its queues.


Please enter your comment!
Please enter your name here