Exchanges & Routing
Routing is the whole job of an exchange
Section titled “Routing is the whole job of an exchange”An exchange stores nothing. Its one job is routing: take a published message and decide which queues get a copy. How it decides is set by the exchange’s type. Learn the four types and you can express almost any message-flow topology.
What this module covers
Section titled “What this module covers”| Lesson | The exchange decides by… |
|---|---|
| Direct exchange | An exact routing key match |
| Fanout exchange | Nothing — it copies to every bound queue |
| Topic exchange | A pattern match on a dotted routing key |
| Headers & choosing | Message headers, plus a guide to picking a type |
The four types at a glance
Section titled “The four types at a glance”flowchart TB msg["message routing key: order.created"] --> direct["direct match key exactly"] msg --> fanout["fanout ignore key, copy to all"] msg --> topic["topic match key pattern"] msg --> headers["headers match on header values"]
The mental model to carry through this module:
- A message always carries a routing key (a string like
order.created) and optional headers. - Each binding from an exchange to a queue may carry a binding key (or pattern, or header conditions).
- The exchange type is the rule that compares the message against the bindings to pick queues.
Everything else — pub/sub, work distribution, event filtering — is just a choice of exchange type plus some bindings.