New RabbitMQ users often ask whether they should "send to an exchange or a queue", or whether a topic is a kind of queue. The confusion is normal: in most other messaging systems, you publish directly to the thing you read from. RabbitMQ splits that in two. This article explains the split, why it exists, and how to use it.
Publishers always publish to an exchange. Consumers always read from a queue. Bindings decide which queues get which messages.
publisher ──► exchange ──(binding)──► queue ──► consumer
└────(binding)──► queue ──► consumerAn exchange is like a post office sorting desk. It looks at the message (its routing key, sometimes its headers), checks its list of bindings, and puts a copy in every queue that matches. Then it forgets about the message.
Key properties:
mandatory flag, or sent to an alternate exchange).A queue is an ordered buffer of messages, waiting to be delivered to consumers.
A binding says "exchange X sends messages matching pattern P to queue Q". For a direct exchange, the pattern is an exact routing key. For a topic exchange, it can contain wildcards. For a fanout exchange, it's ignored.
Bindings are what make RabbitMQ flexible. The publisher doesn't know which queues exist. You can add a new consumer with its own queue and a new binding without touching the publisher.
| Exchange | Queue | |
|---|---|---|
| Role | Routes messages | Stores messages |
| Who talks to it | Publishers | Consumers |
| Holds messages | No | Yes |
| Types | direct, topic, fanout, headers | classic, quorum, stream |
| One message goes to | Every matching queue | One consumer (or every stream consumer) |
| Can be durable | Yes (the definition survives restarts) | Yes (definition and persistent messages survive restarts) |
| Can be deleted while in use | Yes, messages to it are then lost | Yes, its messages are lost |
If you come from Kafka, JMS or a cloud service, you may look for "topics" in RabbitMQ and find a topic exchange. It's not the same thing.
To get pub/sub in RabbitMQ, give each subscriber its own queue and bind all those queues to the same exchange. Each queue receives a copy:
┌──► queue "billing" ──► billing service
publisher ──► exchange ├──► queue "emails" ──► email service
"events" (topic) └──► queue "analytics" ──► analytics serviceTo get point-to-point (work queue), have several consumers read the same queue. RabbitMQ distributes messages between them.
To get Kafka-like behaviour (many readers of the same stored data, replay), use a stream. We compare the models in more detail in RabbitMQ vs Kafka.
Sort of. Every RabbitMQ virtual host has a default exchange, a direct exchange with an empty name (""). Every queue is automatically bound to it with a routing key equal to the queue name. So this:
channel.sendToQueue('emails', Buffer.from('hello'));is really this:
channel.publish('', 'emails', Buffer.from('hello'));The default exchange is perfect for simple cases (one producer, one queue, RPC replies). It becomes limiting when a second service wants the same messages: the publisher has to change to send twice. Publishing to a named exchange from day one costs one line and keeps that door open.
You can't bind or unbind anything to the default exchange, and you can't delete it.
One orders exchange, two services that need order events, and a work queue shared by two instances of the billing service:
// setup (run once, or at startup of each service)
await ch.assertExchange('orders', 'topic', { durable: true });
await ch.assertQueue('billing', { durable: true, arguments: { 'x-queue-type': 'quorum' } });
await ch.bindQueue('billing', 'orders', 'order.created');
await ch.assertQueue('emails', { durable: true, arguments: { 'x-queue-type': 'quorum' } });
await ch.bindQueue('emails', 'orders', 'order.*');
// publisher: knows only the exchange
ch.publish('orders', 'order.created', Buffer.from(JSON.stringify({ id: 42 })), { persistent: true });
// consumers: know only their queue
// billing instance 1 and billing instance 2 both run this, and share the messages
await ch.prefetch(10);
await ch.consume('billing', async (msg) => {
await charge(JSON.parse(msg.content.toString()));
ch.ack(msg);
});order.created lands in both billing and emails. order.shipped only lands in emails.
As soon as you have more than a handful of exchanges, the hard question becomes "which queues will this message reach?". The management UI lists bindings per exchange and per queue on separate pages, so following a message across exchange-to-exchange bindings, dead-letter exchanges and alternate exchanges means opening many tabs.
For a visual approach, see how to visually explore RabbitMQ queue bindings.
An exchange routes messages to queues using bindings and stores nothing. A queue stores messages until consumers acknowledge them.
Every message goes through one. If you publish "to a queue", you are using the default exchange (""), which routes by queue name.
Yes. Exchange-to-exchange bindings let you build routing hierarchies, for example a topic exchange that forwards some messages to a fanout exchange.
It's dropped silently. Use the mandatory publish flag to get it back, or an alternate exchange to send it to a catch-all queue.
No. A RabbitMQ topic exchange is a routing rule. A Kafka topic is a stored log. RabbitMQ streams are the closest equivalent to Kafka topics.
Visualize and navigate bindings, dead-letter and alternate exchanges without jumping between pages.
Explore my bindingsAvailable on Windows, Mac, and Linux.
RabbitMQ tutorialRabbitMQ topic exchange: routing key wildcards explainedHow the RabbitMQ topic exchange matches routing keys with * and
RabbitMQ tutorialRabbitMQ 3.x end of life: what it means and how to upgrade to 4.xRabbitMQ 3.13 lost community support in 2024. Here are the support dates for every series, the risks of staying, the 4.0 breaking changes and a step-by-step upgrade path to 4.x.
RabbitMQ tutorialMessages stuck in a RabbitMQ queue? 7 causes and how to fix themMessages piling up in RabbitMQ and not consumed? Diagnose missing consumers, stuck unacked messages, prefetch, slow consumers, poison messages, alarms and routing mistakes, with the commands to check each one.
RabbitMQ tutorialRabbitMQ queue types: classic vs quorum vs streamWhich RabbitMQ queue type should you use? Classic, quorum and stream queues compared on replication, data safety, ordering, features and performance, for RabbitMQ 4.x.
RabbitMQ tutorialRabbitMQ health checks: CLI, HTTP API, Docker and KubernetesCopy-paste RabbitMQ health checks. rabbitmq-diagnostics commands, /api/health endpoints, a Docker Compose healthcheck and Kubernetes probes that don't hurt your cluster.
RabbitMQ tutorialThe RabbitMQ Management UI: a complete guideHow to enable the RabbitMQ management plugin, open the UI on port 15672 (Docker too), log in, and what each tab does, plus its limits.