Difference between revisions of "Rabbit MQ"
(Created page with "Category:RabbitMq Category:MessageQueue == Standard RabbitMQ message flow == # The producer publishes a message to the exchange. # The exchange receives the message a...") |
(No difference)
|
Latest revision as of 15:11, 20 October 2025
Contents
Standard RabbitMQ message flow
- The producer publishes a message to the exchange.
- The exchange receives the message and is now responsible for the routing of the message.
- Binding must be set up between the queue and the exchange. In this case, we have bindings to two different queues from the exchange. The exchange routes the message into the queues.
- The messages stay in the queue until they are handled by a consumer.
- The consumer handles the message.
Exchange Types
RabbitMQ has four main exchange types for routing messages: Direct, which routes to queues with matching routing keys; Fanout, which broadcasts messages to all bound queues; Topic, which uses wildcard pattern matching to route messages; and Headers, which routes messages based on matching message header attributes. There is also a special, unnamed Default Exchange that acts as a direct exchange for simplicity.
Direct Exchange
- How it works: Routes messages to queues where the message's routing key is an exact match for the queue's binding key.
- Use case: Distributing tasks to workers.
Fanout Exchange
- How it works: A copy of the message is sent to every queue that is bound to it, regardless of routing keys.
- Use case: Broadcasting messages, such as news updates or sports commentary.
Topic Exchange
- How it works: Uses wildcard matching between a message's routing key and a pattern defined by the queue's binding key.
- Wildcard patterns: * matches one word, and # matches zero or more words.
- Use case: Routing messages to multiple queues based on hierarchical routing keys.
Headers Exchange
- How it works: Routes messages based on matching header arguments and attribute values rather than the routing key.
- Use case: When routing logic is based on message headers rather than a simple string.
Default Exchange
- How it works: An unnamed, pre-declared direct exchange where the routing key of the message must match the name of the queue for the message to be routed.
- Use case: Simple applications where queues can be bound to the default exchange using their queue names as the routing key.
Dead Letter Exchange
If no matching queue can be found for the message, the message is silently dropped. RabbitMQ provides an AMQP extension known as the "Dead Letter Exchange", which provides the functionality to capture messages that are not deliverable.
Bindings
See : https://www.cloudamqp.com/blog/part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html