RabbitMQ: Examples of RabbitMQ usage

This documentation is part of the Introduction guide. View the full guide here: Introduction to Stackhero for RabbitMQ.

Imagine an application that allows users to download all invoices from the past year with a single action. This task involves generating multiple PDF invoices simultaneously, which can be quite time-intensive. With RabbitMQ, an application can dispatch 12 messages carrying invoice details to a topic. A dedicated invoice generation system will then respond to these messages, produce the PDF files, and return them to RabbitMQ. Subsequently, the app retrieves the PDFs and delivers them to the client.

The true power of this system lies in its ability to run multiple scripts concurrently to generate invoices. With the same code, you can process these 12 invoices in parallel! Imagine 100 users each requesting their latest 12 invoices at the same time. No worries, the system is now equipped to scale and handle numerous PDF files simultaneously!

Now, suppose you wish to email these invoices. You can create a script that accepts an email address and a PDF file as inputs, then sends the PDF to the specified email. Connect this emailing script to RabbitMQ and configure your invoice generator to forward the PDF files to the topic "emails". It is as simple as that. The app can now generate and email dozens of invoices efficiently.

Reliability is another key advantage. If an email script crashes unexpectedly while sending an invoice, RabbitMQ ensures the invoice is not lost. Another email script can pick up the task and complete it seamlessly, maintaining user satisfaction. RabbitMQ bolsters both reliability and consistency.

There are countless use cases. If you have multiple systems or applications requiring reliable communication, or if you need to delegate time-consuming tasks to other systems, RabbitMQ could be the solution you need.

In apps like Uber or Lyft, when a user requests a ride, several pieces of information are presented:

  • The price of the ride
  • The duration of the ride
  • The estimated pickup time
  • The route

These components can be divided into separate services, with RabbitMQ facilitating inter-service communication. When a user requests a ride, the starting point and destination are sent to these services, which compute the necessary data in parallel. Results are then displayed to the user as they become available. If calculating the ride duration takes longer, the remaining information will still be shown promptly, minimizing user frustration.

Similarly, in apps like GrubHub or Deliveroo, when a user selects food, several details are displayed:

  • Food availability
  • Estimated delivery time
  • Total cart price

As in the Uber/Lyft example, these aspects can be handled by separate services, using RabbitMQ to manage message exchanges.