What is Rabbit MQ?

In modern applications, instead of a Monolith, there is a gradual shift in companies’ ideology toward a micro-service-based architecture. Decoupled modules are essential to ensure this workload is smooth and fast. Message brokers allow your applications to communicate and decouple from each other.

A message could contain any information. For instance, information about a task or process that should start on another application. This target application could be located on another server precisely optimized for such tasks. A queue-manager stores the messages until a receiving application connects to dequeue the message.

The message queue

RabbitMQ is an open-source message broker that deploys a message queuing mechanism between two applications. It takes messages from the publisher and relays them to the consumer. RabbitMQ is highly scalable and offers temporary storage for data.

A broker can also reduce loads and delivery times on web application servers besides relaying these messages. Time or resource-intensive tasks can easily be delegated to a third party with no other job.

How a RabbitMQ Queue works

A RabbitMQ Queue is a form of sequential data structure. An item is enqueued at the end and dequeued from the head, following a FIFO (First in First Out) principle. Although the RabbitMQ queue also offers unique features like priorities and re-queueing.

Publishers and Consumers pass information using this data mechanism. The applications pick a queue by name to distinguish between 2 RabbitMQ queues.

The message flow in RabbitMQ

In the basic architecture of a queue, Client applications ( also called producers ) create messages and deliver them to the broker ( the message queue). Consumers (often service workers) connect to the queue and pick up the messages to be processed. A single software can act as both a consumer and producer of messages.

Although the message flow in RabbitMQ is similar to the architecture described above, RabbitMQ has some unique features.

In RabbitMQ, the messages are published to an exchange. The exchange receives the message and is tasked with routing the message to the correct queue. Attributes like this routing number, exchange type and queue name are used to create bindings from exchange to queues. The message is ultimately routed and enqueued at the end of the queue, which stays until a consumer handles it.

Use cases for Message Queues with Rabbit MQ

  • Sending emails and email notifications
  • Running specific functions on a schedule
  • Run machine learning inference or training
  • Offloading any long-running tasks
  • Backing up a database
  • Generating any reports that take 3+ seconds to create
  • Powering up/down additional virtual machines for load handling
  • Triggering workflows
  • Sending webhook notifications

Conclusion

Are expensive computation and time-consuming tasks bogging down your web applications? Or you want to keep up with the practice of micro-service-based architecture.

Then, a well-configured message queue like RabbitMQ should feature on your tech stack. It uses a FIFO method and ensures that messages do not leave the queue unless a consumer picks them up.