awesome-everything RU
↑ Back to the climb

Queues, Streams, Eventing

RabbitMQ exchanges: config and routing reading

Crux Read real RabbitMQ binding configs and routing snippets, predict which queues receive a copy, and pick the fix a senior engineer would make first.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

Routing bugs are read in the binding table and the publish call, not in a stack trace — there usually isn’t one. Read each config and snippet, then choose the behaviour or fix a senior engineer would land first.

Goal

Practise the loop you run in every routing incident: read the exchange type and bindings, predict which queues get a copy, and reach for the correct fix before guessing at the producer.

Snippet 1 — topic bindings

exchange: events  (type: topic)

bindings:
  Q_audit   <- "order.#"
  Q_eu      <- "order.*.eu"
  Q_created <- "order.created.*"

publish routing key: "order.created.eu"
Quiz

With routing key order.created.eu published to the topic exchange events, which queues receive a copy?

Snippet 2 — the prefetch config

channel.basic_qos(prefetch_count=1000)   # one channel, many consumers
channel.basic_consume(queue="jobs", on_message_callback=handle)
# handle() does slow CPU-bound work, ~200ms per message
Quiz

Several workers consume jobs with this config and work is unevenly distributed while broker memory climbs. What is the defect and the fix?

Snippet 3 — the dead-letter config

declare queue "work" with arguments:
  x-dead-letter-exchange: "dlx"
  x-message-ttl: 30000          # 30s

exchange "dlx" (type: fanout)  ->  queue "work.dead"

consumer on "work": on failure -> channel.basic_nack(requeue=True)
Quiz

A poison message keeps looping on queue work and never reaches work.dead despite the dead-letter config. Why?

Snippet 4 — the default exchange

# no exchange declared; publish with empty exchange name
channel.basic_publish(exchange="", routing_key="reports", body=payload)
# a queue named "reports" exists but is ALSO bound to a topic exchange "events"
Quiz

Where does this message go, given the empty exchange name and routing key reports?

Recap

Routing is read in the binding table, not the stack trace: topic patterns match independently and every match yields a copy (* is exactly one word, # is zero or more); a too-high prefetch reserves a large unacked batch on one consumer and starves the rest; dead-lettering only fires on reject/expire, so nack-with-requeue loops a poison message forever; and the empty-string exchange is the default direct exchange where the routing key is the queue name. Read the type and bindings first, predict the copies, then fix.

Continue the climb ↑RabbitMQ exchanges: build an order-events routing fabric
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources1
expand
  1. 01

Trademarks belong to their respective owners. Editorial reference only.