Damián Pumar

← Back to blog

Published on May 11, 2024 by Damián Pumar

RabbitMQ in 5 minutes

Rabbitmq is an open source messaging broker that allows applications to communicate with each other asynchronously.

Producing and Consuming

In RabbitMQ, there are two main roles:

  • Producer: The application that sends a message to RabbitMQ.
  • Consumer: The application that receives a message from RabbitMQ.

Queues

A queue is a buffer that stores messages sent by producers and waits to be processed by consumers. Queues are the basic unit of storage in RabbitMQ.

Exchanges

An exchange is the component that receives messages from producers and sends them to the appropriate queues. Exchanges are like “distribution hubs” that direct messages to the correct queues.

Types of Exchanges

There are four types of exchanges in RabbitMQ:

  • Direct Exchange: Sends the message to the queue that exactly matches the specified routing key.
  • Fanout Exchange: Sends the message to all queues bound to the exchange.
  • Topic Exchange: Sends the message to queues that match the specified routing key, using a pattern-matching system (e.g. .orders.).
  • Headers Exchange: Sends the message to queues that match the message headers.

Bindings

A binding is the relationship between a queue and an exchange. Bindings define how messages are sent from the exchange to the queue.

Routing Key

The routing key is a string used to determine which queue to send the message to. Producers specify the routing key when sending a message.

Message Acknowledgement

When a consumer processes a message, it must send an acknowledgement to RabbitMQ to indicate that the message has been processed successfully. If the consumer fails before processing the message, RabbitMQ re-sends the message to the queue.

Other Concepts

  • Virtual Host: A virtual host is a logical namespace that separates applications using RabbitMQ.
  • Channel: A channel is a logical connection between an application and RabbitMQ. Channels are used to send and receive messages. That’s it! In summary, RabbitMQ is a message broker that uses exchanges, queues, bindings, and routing keys to direct messages between producers and consumers. Consumers process messages and send acknowledgements to RabbitMQ.

Hope you like it, see you in the next post 👋

Bye 🙌

Written by Damián Pumar

Something wrong? Let me know 🙏

← Back to blog