Blog.

RabbitMQ

RabbitMQ is a message broker that is used to distribute messages between different applications and services. It is a very popular messaging system that is used by many companies and organizations.

Why RabbitMQ?

Clustering and load balancing

Clustering is a very important part of the architecture of a distributed system, and RabbitMQ is one of the most popular message brokers that is used in the industry. It allows us to distribute messages between different applications and services, it also allows us to scale up and down the number of workers that are processing the messages with the particularity of providing a load balancing mechanism out of the box and managing any failures that might occur.

Management UI

It has a very nice management UI that allows us to manage the messages and the queues that are being used by the application without having to go to the command line. It provides several data that might help us to understand the state of the system and the messages that are being processed like the number of messages that are being processed, message rates, etc.

Plugins

It has an extensive set of plugins that allow us to customize the way RabbitMQ works, and it has a management UI that allows us to manage the whole system from a single interface and if you don't find the features you need, you can easily create your own plugins.

The AMQP protocol

The AMQP protocol is a standard for the communication between applications and services. It is used to send and receive messages between applications and services. The AMQP stands for Advanced Message Queuing Protocol and it's a way to define the messages format like the headers, the content type, the message properties, etc.

Exchange types

The exchange types are:

  • Direct
  • Topic
  • Fanout
  • Headers

How to choose an exchange type

The exchange type is the way the messages are distributed between the applications and services, and it is important to choose the right one for the project.

If you have a system that is used by many applications, you should use a fanout exchange type, because it will distribute the messages to all the applications that are connected to the same exchange. Example: You have a game with a scoreboard and when there's a new score, you want to send it to all the applications informing them that there is a new score.

If you have a system that is used by only one application or service, you should use a direct exchange type, because it's the simplest one, and it will distribute the messages to the application or service that is connected to the exchange. Example: A service that converts a video or an image to a different format, you want to send it to the queue and the worker that's connected and available to process the message will do the job.

If you have a complex system that is used by many applications, you should use a topic exchange type, because it will distribute the messages to the applications that are connected to the exchange, and it will be able to match the messages to the applications that are connected to the exchange. Example: If your application has a feature based on location, and you want the queue to be filtered/distributed to the right application, you should use a topic exchange type to match the messages to the right application.

Finally, if your projects don't fit any of the above, you should use a headers exchange type, usually, this approach is the most complex and has the highest learning curve but has some advantages like the control over the headers.