Sitemap

What is Message Broker and RabbitMQ?

4 min readOct 5, 2023

--

Hello, in this article I will talk about what is message queue and one of the most popular message broker technologies which is RabbitMQ.

First of all we should understand what is message queue, why use it. In software systems, we need to communicate between the services. The message queues provide us a structure to communicate between to distributed architectures and process operations asynchronously. Each message is processed only once, by a single consumer. Advantages of message queues reduce dependency between the services and increase scalability.

When a message sent to the queue, message queue keep the message and process it. Here, the main meaning of the message is the data sent by the publisher for processing.

What is Producer and Consumer?

Services that send messages to the queue are called publisher/producer. Services that receive and process messages from the queue are called consumer.

Messages in the message queue are processed sequentially by the consumer. (FIFO)

What is Message Broker?

It is a system that contains a message queue and provides communication between this queue and the publisher and consumer. In a message broker there might be one more than queue.

What is RabbitMQ?

RabbitMQ is one of the most popular message broker technologies widely used as open source. It supports multiple messaging protocols and streaming. RabbitMQ runs on many operating systems and it has cloud service.

Since RabbitMQ is a message broker, it is used by the publisher who publishes the messages and the consumer who receives and processes the message from the queue. It is learned through exchange which queue the message will go to. It is no matter the programming language of publisher or consumer services developed. They are all seperate and independent.

What are the components of RabbitMQ?

Publisher: The service/application who sends the message to the queue.

Exchange: It is the structure used to determine how the messages sent by the publisher will be managed and to which routes they will be directed.

Routes: It provides us determine which message will send to which queue.

Bindings: Creating a connection between exchange and queue.

Consumer: The service/application who receive and consume the message from the queue.

Exchange Types

There are 4 types of exchange in RabbitMQ. RabbitMQ use Direct Exchange as default behaviour.

Direct Exchange: A Direct Exchange delivers the messages to the queue based on routing key. You can give the queue name to the routing key of exchange. A queue binds to the exchange with a routing key.

Fanout Exchange: In this exchange type, the message is sent to all queues bind to the exchange. Routing key is ignored. If you want to send the published message to all queues ideal way is using the Fanout Exchange.

Topic Exchange: Allowing us to send messages according to the subject. Topic exchange sends the messages based on routing key and routing key patterns.

Header Exchange: This exchange type delivers the messages to queues using headers instead of routing key. In the binding between exchange and queue, a specific argument termed “x-match” indicates whether all headers must match or only one. If “x-match” key’s value is “all” that means is all header values must match. If value of “x-match” key is “any” it means that one header value is enough to match.

Why we should RabbitMQ?

RabbitMQ can be used to provide scalable environment in the software systems. They can be used to reduce loads and delivery times of web application servers by delegating tasks that would normally take up a lot of time or resources to a third party. Also sometimes we need to asynchronous structure in software systems. RabbitMQ provide us this asynchronous.

Resources

--

--

No responses yet