---
topic: system-design
author: Crashtech Editorial
published: Nov 13, 2026 · read: 3 min
---

RabbitMQ Routing: Direct, Topic, Fanout, and Why Producers Never Touch Queues

In RabbitMQ a producer publishes to an exchange, not a queue. Bindings and exchange type decide where each message lands. Here is how the routing really works.

– –

Newcomers to RabbitMQ keep trying to write to a queue. You cannot, by design. The producer talks to an exchange, and the exchange decides which queues get a copy. Understanding that one extra hop explains every routing behaviour in the system.

The moving parts

  • Producer: the application that publishes messages.
  • Exchange: the router. It receives messages and applies routing rules.
  • Binding: a rule that links an exchange to a queue, optionally with a binding key.
  • Queue: the buffer that holds messages until a consumer takes them.
  • Consumer: the application that reads from a queue, processes the message and acknowledges it.

The producer attaches a routing key to each message. The exchange compares that key to the bindings and decides where copies go.

Three exchange types you will actually use

Direct exact match
The message goes to every queue whose binding key equals the routing key. A binding of payment.failed receives only messages published with the key payment.failed. Simple and fast, ideal for work queues by task type.
Topic pattern match
Routing keys are dot-separated words such as orders.eu.created. In a binding, * matches exactly one word and # matches zero or more words. So orders.*.created gets every region’s created events, and orders.# gets everything about orders.
Fanout broadcast
The routing key is ignored. Every bound queue receives its own copy of every message. Use it when several independent systems all need the same event.
Headers attribute match
Routes on message header values instead of the key. Less common, useful when routing depends on several attributes at once.

A worked example

Say you publish order events with keys like orders.eu.created and orders.us.cancelled, to a topic exchange called events.

QueueBinding keyReceives
eu-fulfilmentorders.eu.*all EU order events
all-cancellationsorders.*.cancelledcancellations from every region
auditorders.#every order event

One publish of orders.eu.cancelled lands in all three queues. The producer did nothing special. When finance wants a new feed next quarter, you add a queue and a binding. No producer change, no redeploy.

Unroutable messages vanish quietly

If no binding matches, RabbitMQ drops the message by default. Publish with the mandatory flag so you get it back, or set an alternate exchange as a catch-all. Silent loss during a typo in a routing key is one of the most common messaging bugs.

Advertisement

What happens on the consumer side

A queue holds messages until a consumer takes one and acknowledges it. If the consumer dies before acking, the broker redelivers the message to another consumer. That gives you at-least-once delivery, which means consumers must be idempotent. Two more settings matter in practice: mark queues and messages durable if they must survive a broker restart, and use prefetch limits so one slow consumer does not hoard a backlog.

Do

Design routing keys as a hierarchy (domain.region.event) so topic bindings stay expressive as you add consumers.

Don't

Use fanout for everything “to be safe”. Every bound queue stores a full copy, so you pay in memory and processing for messages a consumer will just discard.

Takeaway

The exchange is the design. Pick the type that matches how consumers want to subscribe: exact (direct), by pattern (topic), or to everything (fanout). Then treat unroutable messages and consumer idempotency as first-class concerns, because that is where RabbitMQ systems actually fail.

Advertisement

Frequently asked questions

Do producers send messages directly to a RabbitMQ queue?

No. Producers publish to an exchange. The exchange applies its routing rules using bindings and the message's routing key, then delivers copies to matching queues. Consumers read from queues. The producer never needs to know which queues exist, which is the whole point of the decoupling.

What is the difference between a direct and a topic exchange?

A direct exchange routes a message to queues whose binding key exactly equals the message's routing key. A topic exchange routes by pattern: a star matches exactly one word and a hash matches zero or more words, with words separated by dots. Topic is direct with wildcards.

What happens to a message if no queue is bound that matches?

By default the message is silently dropped. You can publish with the mandatory flag so unroutable messages are returned to the publisher, or configure an alternate exchange to catch them. Assuming delivery without checking is a classic way to lose data.

When would I use a fanout exchange?

When every interested consumer needs every message and routing keys are irrelevant: broadcasting cache invalidations, pushing notifications to several independent services, or feeding both a search indexer and an audit log from the same event. Each bound queue gets its own copy.

Sources & further reading

/* Comments */