1.Exchanges, queues, routing keys and bindings
RabbitMQ separates "where a message goes" from "who reads it": a producer never publishes directly to a queue, only to an exchange, which routes the message to zero or more bound queues based on a routing key and the exchange's type. A direct exchange routes on an exact key match, fanout broadcasts to every bound queue ignoring the key, and topic matches the key against a wildcard pattern — three genuinely different fan-out shapes from the same core building blocks.
Key features
- Exchange: receives published messages and routes them to queues — a producer publishes to an exchange, never directly to a queue
- Queue: holds messages until a consumer reads and acknowledges them
- Binding: a rule connecting an exchange to a queue, often with a binding key that a message's routing key is matched against
- Direct exchange: routes a message to queues whose binding key exactly matches the message's routing key
- Fanout exchange: broadcasts a message to every queue bound to it, ignoring the routing key entirely
- Topic exchange: matches the routing key against a wildcard binding pattern (e.g. "orders.*.created"), enabling flexible multicast routing
The three common exchange types
- Producer — publishes once
- leads to Exchange (publish)
- Exchange — fanout, ignores key
- leads to email-notifications (copy)
- leads to inventory-updates (copy)
- leads to analytics-events (copy)
- email-notifications
- inventory-updates
- analytics-events
Command
producer → exchange "orders" (topic)
├─ binding "orders.us.*" → queue A
├─ binding "orders.*.vip" → queue B
└─ binding "orders.eu.*" → queue C
publish(routing_key="orders.us.vip") → matches A AND BA producer publishes to an exchange, never directly to a queue. Direct exchanges match the routing key exactly, fanout ignores the key and broadcasts, topic matches wildcard patterns — bindings connect an exchange to the queues that should receive matching messages.