Skip to main content
Version: Next

Sender-selected Distribution

An AMQP publisher can optionally send a message with multiple routing keys. During routing, RabbitMQ will take all routing keys provided in the message headers into account.

For example, if an AMQP publisher sends a message with multiple routing keys to the default exchange, each routing key represents a queue name, and RabbitMQ routes the message to all specified queues.

In another example, if an AMQP publisher sends a message with multiple routing keys to a topic exchange, each routing key represents a topic.

Including multiple routing keys in a message allows it to be routed to more queues, depending on how the queues are bound to the exchange. RabbitMQ settles the message with the accepted outcome if it is routed to at least one queue and all queues confirm receipt. In other words, RabbitMQ accepts the message even if only a subset of the routing keys results in successful routing.

AMQP 1.0

To use multiple routing keys in AMQP 1.0, the publisher sets a message annotation with the key x-cc and the value as a list of strings. Each string in the list represents an additional routing key.

These "CC" routing keys are used in addition to the routing key provided in the AMQP address string.

AMQP 0.9.1

To use multiple routing keys in AMQP 0.9.1, the publisher sets the "CC" and "BCC" header keys. This is similar to specifying multiple recipients in the "CC" or "BCC" fields of an email. The value for "CC" and "BCC" must be an array of strings (longstr values).

The message will be routed using both the routing key supplied as a parameter to the basic.publish method and the routing keys provided in the "CC" and "BCC" headers. The "BCC" key and value will be removed from the message prior to delivery, ensuring some level of confidentiality among consumers.