RABBITMQ

Gayathri siva
5 min readNov 11, 2019

RabbitMQ is an AMQP messaging broker and it is the most popular open source and cross-platform message broker.

RabbitMQ is also known as message-queueing software. Simply said; it is software where queues are defined, to which applications connect in order to transfer a message or messages.

RabbitMQ is also a way to exchange the data between different platform applications such as a message sent from .Net application can be read by a Node.js application or Java application.

The RabbitMQ is built on Erlang general-purpose programming language and it is also used by WhatsApp for messaging.

The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented and the features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security.

It was developed by JPMorgan and iMatix Corporation. AMQP was designed with the following main characteristics as goals:

  • Security
  • Reliability
  • Interoperability
  • Standard
  • Open

RabbitMQ is lightweight and easy to deploy on available premises and it supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements.

RabbitMQ will act as a mediator between producer and consumer

Why and when to Use RabbitMQ?

Now a days most people will perform a multiple tasks in single application like sending emails or SMS, reports and it will create a heavy load on application so if you separate these tasks, then we will get more space (memory) to serve more requests.

By using RabbitMQ, we can remove some heavy work from our web applications such as sending a reports in Excel or Pdf format’s or sending an email, SMS or another task such as trigger some other applications to start processing.

RabbitMQ is an open source and cross-platform message broker so it’s easy to use with many languages such as .Net, Java, Python, Ruby, Node.Js.

RabbitMQ Supported Client Libraries

RabbitMQ will support multiple operating systems and programming languages. RabbitMQ has provided a various client libraries for following programming languages.

  • .Net
  • Java
  • Spring Framework
  • Ruby
  • Python
  • PHP
  • Objective-C and Swift
  • JavaScript
  • GO
  • Perl

EXCHANGES

Messages are not published directly to a queue; instead, the producer sends messages to an exchange. An exchange is responsible for routing the messages to different queues with the help of bindings and routing keys. A binding is a link between a queue and an exchange.

Message flow in RabbitMQ

  1. The producer publishes a message to an exchange. When creating an exchange, the type must be specified. This topic will be covered later on.
  2. The exchange receives the message and is now responsible for routing the message. The exchange takes different message attributes into account, such as the routing key, depending on the exchange type.
  3. Bindings must be created from the exchange to queues. In this case, there are two bindings to two different queues from the exchange. The exchange routes the message into the queues depending on message attributes.
  4. The messages stay in the queue until they are handled by a consumer
  5. The consumer handles the message.

RabbitMQ Exchange Types

In rabbitmq, we have a four type of Exchanges are available to route the message in different ways.

Following are the different type of exchanges available in rabbitmq.

  • Direct
  • Fanout
  • Topic
  • Headers

Direct: The message is routed to the queues whose binding key exactly matches the routing key of the message. For example, if the queue is bound to the exchange with the binding key pdfprocess, a message published to the exchange with a routing key pdfprocess is routed to that queue.

Fanout: A fanout exchange routes messages to all of the queues bound to it.

Topic: The topic exchange does a wildcard match between the routing key and the routing pattern specified in the binding.

Headers: Headers exchanges use the message header attributes for routing.

RABBITMQ AND SERVER CONCEPTS

Some important concepts need to be described before we dig deeper into RabbitMQ. The default virtual host, the default user, and the default permissions are used in the examples, so let’s go over the elements and concepts:

  • Producer: Application that sends the messages.
  • Consumer: Application that receives the messages.
  • Queue: Buffer that stores messages.
  • Message: Information that is sent from the producer to a consumer through RabbitMQ.
  • Connection: A TCP connection between your application and the RabbitMQ broker.
  • Channel: A virtual connection inside a connection. When publishing or consuming messages from a queue — it’s all done over a channel.
  • Exchange: Receives messages from producers and pushes them to queues depending on rules defined by the exchange type. To receive messages, a queue needs to be bound to at least one exchange.
  • Binding: A binding is a link between a queue and an exchange.
  • Routing key: A key that the exchange looks at to decide how to route the message to queues. Think of the routing key like an address for the message.
  • AMQP: Advanced Message Queuing Protocol is the protocol used by RabbitMQ for messaging.
  • Users: It is possible to connect to RabbitMQ with a given username and password. Every user can be assigned permissions such as rights to read, write and configure privileges within the instance. Users can also be assigned permissions for specific virtual hosts.
  • Vhost, virtual host: Provides a way to segregate applications using the same RabbitMQ instance. Different users can have different permissions to different vhost and queues and exchanges can be created, so they only exist in one vhost.

I hope this article helped you gain an understanding of RabbitMQ!

References:

--

--