Course map

Topic 112 / Advanced

RabbitMQ and message routing

Chapter 7.2 · Broker Architectures

What and why

Kafka's log model (→ 111) is not the only broker design — many systems need flexible routing rather than weeks of replayable history. RabbitMQ is the example of a "smart broker, dumb consumer" model: producers publish to an exchange, the exchange applies a routing rule to decide which bound queue(s) receive the message, and each message is removed once a consumer acknowledges it. Builds on: → 109 (publish/subscribe — exchanges are how this broker family implements it).

Diagram

Exchange type Routing rule
Direct Exact routing-key match → one queue
Topic Pattern match (e.g. orders.*.created) → matching queues
Fanout Ignores the routing key, broadcasts to every bound queue
Headers Matches on message header values

How it works

  1. The producer publishes to an exchange with a routing key (and optional headers), not to a queue directly.
  2. The exchange type decides which bound queue(s) get a copy.
  3. Each bound queue holds its own copy of matching messages until a consumer acknowledges them.
  4. Unacknowledged messages, on consumer disconnect, are requeued for redelivery.
  5. Unlike a log, an acknowledged message is gone — there is no built-in replay; routing flexibility is the trade for that.

Practical example

(illustrative). A topic exchange for order events has a billing queue bound to orders.created only, and a fraud queue bound to orders.* (matching both orders.created and orders.cancelled). Publishing orders.created reaches both queues; publishing orders.cancelled reaches only the fraud queue — decided entirely by the binding pattern, not by consumer code.

When to use it

  • Use when task queues and routing-heavy integration are the need, messages aren't needed after processing, and operational simplicity matters more than long retention.
  • Avoid when replay, very high sustained throughput with many independent readers of the same history, or ordering across a large partitioned stream are needed — that's Kafka's strength (→ 111).
  • Failure scenarios: a queue with no consumer and no length limit grows until memory or disk pressure degrades the whole broker; a wrong binding pattern silently discards a message to no queue at all.
  • Simpler alternative: for one producer and one consumer with one routing path, skip the exchange abstraction and point the producer straight at one queue.

Practice

(decision and pattern; 20–30 min — reason from the binding table, or a local single-container broker if available). Design the exchange/binding layout for Project 10's notification platform — one topic exchange, with bindings for email, SMS, and push queues by notification type — then for a "promo" and a "security-alert" message, write out which queues receive each and why. Done when the binding table alone, with no code, correctly predicts every queue's content for 5 sample messages.

Shared lab setup

Key takeaway

RabbitMQ-style brokers put routing intelligence in the broker and discard messages once acknowledged — the opposite trade-off from Kafka's dumb, retained log. Done when you can: choose an exchange type from a routing requirement and state what happens to a message after acknowledgement. Used next in → 113 (event-driven architecture can run over either broker family).

References

None — exchange types are described as uncontested, vendor-neutral broker concepts.

Exercise: For Project 10, sketch the partition and consumer-group layout: partition count, partition key, what consumer lag you alert on, and what happens when a consumer dies mid-batch.

Source directory

Search the guide