RabbitMQ · Concept
Direct, topic and fanout exchanges
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
In RabbitMQ a producer never sends straight to a queue. Explain exchanges, bindings and routing keys. With a topic exchange and these bindings, which queues get a message published with 'order.cancelled.mumbai'? And what changes with a direct or a fanout exchange?
queue refunds bound with order.cancelled.*
queue mumbai-ops bound with *.*.mumbai
queue audit bound with #
queue invoices bound with order.created.*
queue city-alerts bound with order.*
Then
Follow-ups the interviewer asks next
- Which queues get it, and why not
city-alerts? - What does
#match that*doesn't? - What happens to a message that matches no binding?
- Two copies of the refund service read one queue. Who gets each message?
- How do you give every service its own copy of each event?
The answer
What a strong answer covers
- Producers publish to an exchange with a routing key; bindings connect an exchange to queues with a key or pattern; consumers read from queues.
- Topic exchange: words separated by dots;
*matches exactly one word,#matches zero or more. 'order.cancelled.mumbai' goes torefunds,mumbai-opsandaudit.city-alerts(order.*) needs exactly two words, so it doesn't match, and neither doesinvoices. - Direct exchange: the routing key must equal the binding key exactly. Fanout: ignores the key and copies to every bound queue. Headers exchange: matches on message headers. The default exchange routes to the queue whose name equals the routing key.
- Unroutable messages are dropped silently, unless the publisher sets the
mandatoryflag (the broker returns the message) or the exchange has an alternate exchange. - One queue with several consumers = competing consumers: each message goes to one of them. One queue per service, each bound to the exchange = every service gets its own copy (publish-subscribe).
- RabbitMQ 4.x also speaks AMQP 1.0 natively next to AMQP 0-9-1; the routing model is the same.
The red pen
Common traps
Avoid:"RabbitMQ sends to queues directly"; thinking fanout looks at routing keys; not knowing unroutable messages vanish.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.