Skip to main content

Model

RabbitMQ routes a message through an exchange into queues by bindings, and a consumer reads one queue over a channel of a connection.

A producer publishes to an exchange, a binding copies the message into a queue, and a consumer reads the queue; clients talk over channels of one connectionVirtual hostOne TCP connectionProducerpublishes with a routing keyExchangepicks the queues by its bindingsQueueholds messages until a consumer settles themConsumerreads one queueChannel 1Channel 2Channel nEvery publish and every consumer runs on a channel:a light session the connection multiplexes
The diagram as text
  1. Virtual host: Exchange picks the queues by its bindings; Queue holds messages until a consumer settles them
  2. One TCP connection: Channel 1; Channel 2; Channel n
  3. Producer publishes with a routing key → Exchange picks the queues by its bindings: publish
  4. Exchange picks the queues by its bindings → Queue holds messages until a consumer settles them: binding
  5. Queue holds messages until a consumer settles them → Consumer reads one queue: deliver
  6. Every publish and every consumer runs on a channel: a light session the connection multiplexes

A producer never writes to a queue. It publishes to an exchange and gives the message a routing key. The exchange compares the message with its bindings, and every queue whose binding matches gets a copy. A message that matches no binding reaches no queue.

A queue is storage that a consumer empties. A message leaves the queue once its consumer acknowledges it. Until then the server keeps it, and a delivery the consumer gives back or never settles returns to the queue.

Every server has a default exchange with an empty name. Each queue is bound to it under its own name, so a publish to the default exchange with the routing key orders lands in the queue orders. That is how a service with no topology of its own still publishes to a queue.

Exchanges, queues and bindings live in a virtual host, which the connection URI names. A client opens one TCP connection and runs its work on channels inside it. A channel is a light session with state of its own: a prefetch window, a confirm mode, a transaction. An error on a channel closes that channel and leaves the connection up.

The model is AMQP 0.9.1 as RabbitMQ implements it (AMQP concepts, channels, the default exchange). How each exchange type routes is on Exchange types, how a queue pushes to its consumers on Consumers and prefetch, and how the two queue types differ on Classic and quorum queues.