RabbitMQ
medium 32 minRabbitMQ is an open-source message broker.
Video lesson · Chapter 1 of 5
An invoice has to reach its queue
RabbitMQ in 90 seconds
1:30Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
RabbitMQ is a program that takes messages from some applications and delivers them to others. Such a program is called a message broker. Its special strength is routing: a sender does not choose a queue, it describes the message with a routing key, and rules inside the broker decide where copies go.
Those rules are exchanges and bindings. An exchange receives messages. A binding connects it to a queue, perhaps with a pattern. A queue stores messages in order until a consumer takes one and reports, with an acknowledgement, that it is finished.
It speaks several protocols: AMQP 1.0 and AMQP 0-9-1 in the core, its own stream protocol, MQTT and STOMP through plugins that ship with it, and WebSocket variants for browsers. It also has an HTTP interface for management, which is not meant for heavy messaging.
Why it exists
Work that a user need not wait for should be handed over: send the e-mail, resize the picture, charge the card, tell the warehouse. The sender wants to be sure the request is safe, and the workers want it one at a time, at their own speed, with another try when something fails.
When several services care about the same event, the sender should not keep a list of them. With an exchange, a new service binds its own queue and the sender never changes.
A short history
2007
RabbitMQ is first released by Rabbit Technologies, a joint venture of LShift and CohesiveFT, as an open-source AMQP broker.
April 2010
SpringSource, a division of VMware, acquires it. Today it is developed at Broadcom, which owns VMware.
September 2024
The 4.0 series: AMQP 1.0 is a core protocol, mirrored classic queues are gone, and quorum queues get a default delivery limit of 20.
April 2026
RabbitMQ 4.3: Khepri, based on Raft, is the only metadata store. Quorum queues get delayed retries and 32 strict priorities.
October 2026
RabbitMQ 4.4: publishers can delay a message in a quorum queue. Facts on this page are from its documentation.
Words to know
- Exchange
- Receives messages and routes copies of them.
- Binding
- A rule from an exchange to a queue, a stream or another exchange.
- Routing key
- A short text on the message, often words with dots.
- Acknowledgement
- The consumer's message that the work is done, so the queue may delete.
- Publisher confirm
- The broker's message that it has accepted what was published.
- Prefetch
- How many unacknowledged messages one consumer may hold.
- Quorum queue
- A queue copied to several nodes with the Raft protocol.
- Dead-letter exchange
- Where a queue sends messages that were rejected, expired, overflowed or failed too often.
- Virtual host
- A named space with its own exchanges, queues and permissions.
- Channel
- A light session inside one connection, in AMQP 0-9-1.
How it works
Step through the idea, or press Play.
Publish. To an exchange, with a routing key, and wait for the confirm
Understand it
Start here
The pneumatic-tube post room
Imagine an old office with a tube post: capsules blown through pipes. A clerk does not walk to the departments. Each capsule wears a coloured ring, and a sorting box reads the ring.
The sender knows rings, not trays. Trays can be added without telling anyone.
General ideas have their own pages: queues (receipts, dead letters, competing consumers), publish and subscribe, push and pull, retries and idempotency. Here we look at the product.
Purpose
What it is good for
Flexible routing
Exact keys, patterns, broadcast or headers, as configuration instead of code.
Prompt delivery
The broker pushes a message as soon as a consumer has room. Measure the latency on your own network and queue type.
Careful delivery
Publisher confirms, acknowledgements, limits on redelivery and dead letters.
Many protocols
AMQP 1.0, AMQP 0-9-1, MQTT, STOMP and streams on one broker, so devices and services can meet.
Typical uses: background jobs, request and reply between services, event routing, urgent-first queues, delayed messages, and IoT devices over MQTT. The licence is the open-source Mozilla Public License 2.0; commercial support is sold separately.
Architecture
Publisher, exchange, binding, queue, consumer
One message, three queues
The parts
| Part | Job | Note |
|---|---|---|
| Publisher | Sends to an exchange with a key and properties | Holds one long-lived connection |
| Exchange | Finds matching bindings | Stores nothing |
| Binding | Connects, perhaps with a pattern | Many per queue are fine |
| Queue | Keeps messages in order until acknowledged | First in, first out, except for priorities and redeliveries |
| Consumer | Receives, works, acknowledges | Many on one queue share the work |
| Virtual host | Separates tenants or environments | A namespace with permissions; hardware is shared |
Routing
Four kinds of exchange
| Type | Rule | Example | Use |
|---|---|---|---|
| Direct | Key equals binding key | error to the error queue | Tasks by type, logs by severity |
| Topic | Patterns: * one word, # zero or more | order.*.us, order.# | Events in a hierarchy, regions |
| Fanout | Key ignored, all bound queues | A price change for every service | Broadcast |
| Headers | Named headers; x-match all or any | type pdf and size large | Several attributes at once |
Which exchange?
Topic patterns against keys
| Pattern | order | order.created | order.created.us | order.created.shipped.us |
|---|---|---|---|---|
order.* | no | yes | no | no |
order.*.us | no | no | yes | no |
order.# | yes | yes | yes | yes |
#.us | no | no | yes | yes |
Storage
Classic queues, quorum queues and streams
| Classic queue | Quorum queue | Stream | |
|---|---|---|---|
| Copies | One node | Several nodes, Raft | Several nodes |
| After consuming | Deleted on ack | Deleted on ack | Kept until retention |
| Many readers of one message | No, one consumer gets it | No, one consumer gets it | Yes, each at its own offset |
| Failed-delivery limit | No | Yes, 20 by default | Not applicable |
| Good for | Temporary or exclusive queues, data you can lose | Orders, payments, jobs | Fan-out to many, replay, long backlogs |
x-queue-type.A quorum queue has a leader and followers, by default three members in all. A message is confirmed when a majority has it. If the leader's node dies, the others elect a new one. Message bodies are kept on disk, not in memory. Quorum queues are always durable, and cannot be exclusive or server-named.
Majority and losses
A stream is an append-only log, like a Kafka partition. Super streams split it into partitions. Streams complement queues: they bring replay to RabbitMQ, with their own protocol for the best speed.
The path
From publish to acknowledge
At least once, end to end
- 1
Publish
Key, body and properties: content type, delivery mode, message id, headers.
- 2
Match
The exchange evaluates its bindings and places a copy in each matching queue.
- 3
Store and confirm
Classic, durable and persistent: after it is on disk. Quorum: after a majority has it. With several queues, after all of them.
- 4
Deliver
The broker pushes within the prefetch. Each message goes to one consumer of the queue.
- 5
Acknowledge
ackdeletes.nackorrejecteither requeues or, with requeue false, dead-letters or drops. - 6
Fail safely
Rejected, expired, overflowing and endlessly redelivered messages go to the dead-letter exchange.
Where can a message get lost?
| Gap | Closed by |
|---|---|
| Between publisher and broker | Publisher confirms and a resend |
| No binding matches | Mandatory flag or alternate exchange |
| The node restarts | Durable queue, persistent message |
| The node is lost | Quorum queue |
| The consumer crashes | Manual acknowledgement after the work |
| The work always fails | Delivery limit and dead-letter exchange |
| The dead-letter hop itself | At-least-once dead-lettering, a quorum queue option |
Speed
Confirms, prefetch and connections
Confirms can be awaited one by one (simple, slow), for a batch (better, but an error means resending the batch), or handled as they arrive (fastest, a bit more code). Consumer acks can also cover several messages at once.
A first guess for prefetch
Long jobs of uneven size want a prefetch of 1 or 2, so nobody hoards. Short jobs want more: the documentation finds 100 to 300 usually best for throughput. Set it per consumer; quorum queues refuse the older per-channel form.
How many consumers?
One connection, many channels
A connection costs TCP, TLS and login. Keep it open; give each thread its own channel. Separate connections for publishing and consuming, so a blocked publisher does not stop acks.
Heartbeats
The suggested timeout is 60 seconds. They find dead peers that TCP has not noticed.
One queue, one leader
All traffic of a queue passes through its leader. For more, use several queues, for example with a consistent-hash exchange, and lose the order between them.
Failure
Dead letters and retries
A queue with a dead-letter exchange passes on a message when it is rejected without requeue, when its time to live ends, when the queue overflows, or when a quorum queue's delivery limit is passed. Headers record where it came from, why, and how often.
Retrying at once often makes trouble worse. There are two ways to wait:
A ladder of waiting queues
Two ways to delay a retry
| Waiting queues | Delayed retry of quorum queues | |
|---|---|---|
| Needs | Any version, one queue per delay | RabbitMQ 4.3 or later |
| Delays | Any steps you like | Linear: minimum times the delivery count, up to a maximum |
| Counting | Your header | The broker's delivery count |
| Watch out | Publish the copy and wait for the confirm before you ack the original | basic.reject counts as a failure; since 4.3 basic.nack with requeue does not |
Delayed retry
Protection
Back-pressure and limits
Who slows whom?
Limits and defaults in 4.4
| What | Default | Comment |
|---|---|---|
| Memory alarm | 60% of detected RAM | vm_memory_high_watermark.relative |
| Disk alarm | 50 MB free | Fine for a laptop only; raise it a lot in production |
| Largest message | 16 MiB | May be raised to 512 MiB; better to send a link |
| Delivery limit, quorum | 20 | x-delivery-limit |
| Ack timeout, quorum | 30 minutes | Then the message returns to the queue |
| Heartbeat | 60 seconds | Agreed by both sides |
| Stream segment | 500 MB | One file of a stream |
| Ports | 5672, 15672, 15692 | AMQP, management, Prometheus |
Do not wait for the alarm. Give each queue a length limit and choose what happens at the limit: drop the oldest (the default), or reject-publish, which tells the publisher no. Old messages can expire with a time to live.
Cluster
Several nodes
Three nodes, two quorum queues
Every node knows all exchanges, bindings and users. Queue contents are copied only by quorum queues and streams; a classic queue lives on one node. Three nodes in three zones of a region are the usual start. Spread leaders with the balanced leader locator, or rabbitmq-queues rebalance later.
Patterns
Common designs
| Pattern | How | Note |
|---|---|---|
| Work queue | One queue, many consumers | Low prefetch for long jobs |
| Events | Topic exchange, one queue per service | A new service binds its own queue |
| Request and reply | Direct reply-to and a correlation id | Consider RPC if the caller waits anyway |
| Urgent first | Priorities: 32 levels in quorum queues, up to 255 in classic | Keep few levels; prefetched messages are already gone |
| Later | x-opt-delivery-time on quorum queues, since 4.4 | The separate delayed-message plugin was archived in September 2026 |
| Strict order with a spare | Single active consumer | The next consumer takes over |
Operations
Run it
What to watch
| Signal | Healthy | When it is not |
|---|---|---|
| Ready messages, and their age | Short and falling | Add or speed up consumers |
| Unacknowledged messages | About consumers times prefetch | Work hangs, or acks are missing |
| Publish rate and ack rate | Equal over time | A backlog is growing |
| Unroutable messages | 0 | A binding is missing |
| Redeliveries, dead-letter length | Near 0 | Failing work: read the dead letters |
| Memory, disk, file descriptors | Far from limits | Alarms are next |
| Connections and channels, opened per second | Stable | A client opens one per message |
| Quorum members online | All | One more loss may stop the queue |
RabbitMQ is happiest when queues are nearly empty. A long backlog is a sign, or a job for a stream. Upgrade node by node, one release series at a time as the release notes allow: community support for a series is short.
Decide
When to choose it, and when not
Choose RabbitMQ
- Routing by key, pattern or header
- Job queues with acks and retries
- Request and reply, priorities, delays
- MQTT, STOMP and AMQP together
- Prompt push delivery
- On your own machines or any cloud
Choose something else
- Long history with many readers: Kafka, or a stream here
- Event sourcing as the record of truth
- One ordered flow beyond what one leader can carry
- No wish to operate anything: SQS or another managed queue
- Files: object storage with a link
Neighbours
| RabbitMQ | Kafka | Amazon SQS | Redis Pub/Sub | |
|---|---|---|---|---|
| Model | Exchanges and queues, plus streams | Partitioned log | Managed queue | Channels, nothing stored |
| Delivery | Push | Pull | Poll | Push |
| After reading | Deleted on ack (queue) | Stays | Deleted by the consumer | Never stored |
| Guarantee | At least once | At least once; exactly once inside Kafka | At least once; FIFO removes duplicates in a window | At most once |
| Routing | Rich | Topic and key | None in the queue itself | Channel names and patterns |
| Message size | 16 MiB, adjustable | About 1 MB, adjustable | 1 MiB | Not its purpose |
| You pay | Machines and people | Machines and people | Per request | Machines |
Summary
The whole topic in one minute.
RabbitMQ separates sending from storing. Publishers name an exchange and a key, bindings pick the queues, and each queue gives each message to one consumer until it is acknowledged. Direct, topic, fanout and headers exchanges cover most routing without code.
For work that must not be lost use quorum queues, persistent messages, publisher confirms, manual acks and a dead-letter exchange, and expect duplicates. Set prefetch and length limits, watch queue length and alarms, and choose a log such as Kafka, or a RabbitMQ stream, when many readers need the history.
- Publish to an exchange; bindings choose the queues.
- Direct is exact, topic has patterns, fanout is everyone, headers look at attributes.
- Quorum queues copy with Raft; three members survive one loss.
- Confirms protect the sending side, acks the working side, dead letters the line.
- Wait before retrying, count attempts, and expect duplicates.
- Set prefetch and length limits; keep queues short.