RabbitMQ message-broker explained
SENG 41283 — Distributed and Cloud Computing
Most of the software systems moving slowly towards the microservice architecture pattern to overcome many challenges in the traditional monolithic architecture. However, when dealing with the communication between the services in a microservice application you’ll have another set of problems related to handling messages.
Message brokers help to overcome this problem by taking care of the connections between services. A bi-directional connection will be created between each service in the system and message broker. Then message brokers act as a hub like an interface to route the messages to its destinations.
RabbitMQ is an open-source message-broker software which is using AMQP as its protocol.
There are three main entities in RabbitMQ:
Messages are published by a publisher and received by the Exchange in RabbitMQ, then Exchanges will distribute message copies to Queues. To send appropriate messages to the appropriate queues, rules called Bindings are used. Once the messages reach Queues, messages can be delivered to the relevant consumer or consumers can fetch the messages from the Queues.
In case of the message fails to deliver to a consumer, AMQP has a delivery acknowledgement mechanism in place. So a message will not be completely removed from a Queue unless we send a positive acknowledgement from the consumer.
Let’s try a simple worker queue example with RabbitMQ.
As you can see the messages are distributed with the round-robin mechanism in default behaviour. Each worker gets on average the same number of messages.