Introduction to RabbitMQ
Message Broker in Microservices
In the modern design of web services, there is an enormous implementation of microservice. Of course, there is a reason why the microservice design pattern is popular, but let's discuss that on the other occasion.
One of the important ingredients when building microservices is a message broker, it will handle the communication between multiple services. There are several message brokers that many developers use such as Kafka, Redis, NATS, and RabbitMQ. In this article the basics of RabbitMQ will be explained.
Elucidation of RabbitMQ
RabbitMQ is an open-source message broker that acts like a server that actively receives and distributes messages to all servers that are connected to it. There are multiple protocols that can be used to connect RabbitMQ and a server, but the most used one is AMQP.
Microservices contain multiple servers. In an enormous application, the servers can be written in different programming languages. Fortunately, RabbitMQ supports multiple languages so it can unlock a wide range of possibilities.
The Ways of RabbitMQ
There are several ways to distribute messages in RabbitMQ. Using an analogy to understand how messages are distributed in RabbitMQ makes it easy to start learning about them.
Imagine RabbitMQ as a Postal system.
Sending a letter starts with the sender post a letter, then the post office will deliver the letter through the roads to a place according to the information written on it, and finally, the recipient will receive the letter.
In short RabbitMQ works similarly to the postal system above. Of course not exactly the same, in RabbitMQ a publisher (sender) will send a message (letter) through an exchange (post office) then it will be delivered through the routing key (roads) to the queue (place) and consumer (recipient) will consume the message.
The publisher is a server that is connected to RabbitMQ. It will create a message and assign an exchange and a routing key to it. The publisher will send it to the RabbitMQ server.
Inside RabbitMQ server will check the message, first it will be sorted to the exchange assigned to it, this exchange will determine how the message will be delivered according to the type of the exchange. This type of exchange will be discussed on another occasion.
Exchange can be bound with a queue by routing key. Similar to how a place and post office are connected by road. The message will be delivered to the queue that is bound to exchange by the routing key specified in the message before. Finally, the consumer, a server that also connects to RabbitMQ will consume the message in the queue.
Further Topics
Again this is only an introduction to RabbitMQ, there is no code and only concepts in this article to make it easier to understand. The next topics that should be learned are the types of exchange that are mentioned before and the implementation in a specific programming language. The Source of the topics can be directly found in RabbitMQ's Official Tutorial Documentation here.