All Products
Search
Document Center

ApsaraMQ for RabbitMQ:Managing exchanges

Last Updated:Mar 08, 2026

An exchange receives messages from producers and routes them to one or more queues based on routing rules. Each exchange type uses a different routing strategy -- a direct exchange matches routing keys exactly, while a fanout exchange broadcasts to all bound queues. If no queue matches, the exchange discards the message.

Exchange types

Choose the exchange type that matches your routing needs.

Type

Routing behavior

Use when

direct

Routes messages to queues whose binding key exactly matches the message routing key.

You need one-to-one message delivery based on an exact key, such as routing order.created events to a dedicated order processing queue.

topic

Routes messages to queues based on pattern matching between the message routing key and binding patterns. Supports * (matches exactly one word) and # (matches zero or more words) wildcards in dot-delimited routing keys.

You need flexible routing, such as routing logs.error.payment to both a general error queue (bound with logs.error.#) and a payment-specific queue (bound with logs.*.payment).

fanout

Routes all messages to every bound queue, regardless of routing keys.

You need to broadcast messages to multiple consumers, such as pushing notifications to all connected clients.

headers

Routes messages based on message header attributes instead of routing keys. Uses the x-match argument in bindings: set to all to require all headers to match, or any to match at least one header.

You need routing based on multiple attributes rather than a single routing key.

x-delayed-message

Holds messages for a specified duration before routing them. Set the delay in milliseconds using the x-delay message header. The underlying routing strategy is determined by the x-delayed-type parameter.

You need to delay message delivery, such as sending reminder notifications 30 minutes after an event.

x-consistent-hash

Routes messages to queues using consistent hashing on routing keys or header values, distributing load across multiple queues.

You need even message distribution across a set of consumer queues for parallel processing.

Create an exchange

Prerequisites

Before you begin, make sure that you have:

  • An ApsaraMQ for RabbitMQ instance

  • A vhost in which to create the exchange

Procedure

  1. Log on to the ApsaraMQ for RabbitMQ console. In the left-side navigation pane, click Instances.

  2. In the top navigation bar, select the region of your instance. Click the instance name.

  3. In the left-side navigation pane, click Exchanges.

  4. On the Exchanges page, click the Change button next to vhost. From the drop-down list, select the target vhost. Then, click Create Exchange.

  5. In the Create Exchange panel, configure the following parameters and click OK.

    Parameter

    Description

    Exchange Name

    The exchange name. The prefix amq. is reserved and cannot be used. For example, amq.test is not a valid name.

    Type

    The exchange type.

    x-delayed-type

    Required when Type is x-delayed-message. Specifies the underlying routing strategy (direct, topic, fanout, headers, or x-jms-topic).

    Hash value

    Required when Type is x-consistent-hash. Specifies the hash input source: RoutingKey or Header Value.

    hash-header

    Required when Hash value is set to Header Value. Specifies the header key to use as the hash input.

    Internal

    Whether the exchange is internal. Default: No. Set to Yes to create an internal exchange that receives messages only from other exchanges (not from producers directly). Set to No for a standard exchange that binds to queues.

Bind an exchange to a queue

Bind an exchange to a queue to define where the exchange routes messages.

  1. On the Exchanges page, find the exchange and click Bound as Source in the Actions column.

  2. On the Bound as Source tab of the Exchange Details page, click Add Binding.

  3. In the Add Binding panel, set Type of Destination to Bind to Queue, select a queue from the Destination to Bind drop-down list, configure the Routing Key, and click OK.

Note
  • For x-consistent-hash exchanges, the Routing Key value specifies the queue weight (integer from 1 to 20). To change the weight, delete the existing binding and create a new one.

  • If an exchange is bound to the same queue multiple times, only the first matching binding takes effect.

Bind an exchange to another exchange

Forward messages to another exchange (source binding)

Configure the current exchange as a source to forward its messages to a downstream exchange based on routing rules.

  1. On the Exchanges page, find the exchange and click Bound as Source in the Actions column.

  2. On the Bound as Source tab, click Add Binding.

  3. In the Add Binding panel, set Type of Destination to Bind to Exchange, select the destination exchange from the Destination to Bind drop-down list, configure the Routing Key, and click OK.

Receive messages from another exchange (destination binding)

Configure the current exchange as a destination to receive messages from an upstream exchange.

  1. On the Exchanges page, find the exchange and click Details in the Actions column.

  2. On the Exchange Details page, click the Bound as Destination tab. Click Add Binding.

  3. In the Add Binding panel, select the source exchange from the Source Exchange drop-down list, enter a routing key, keep the default values for Type of Destination to Bind and Destination Exchange, and click OK.

Send a message

After binding an exchange, you can send messages from the exchange to bound queues or from a destination exchange to a source exchange in the ApsaraMQ for RabbitMQ console.

  1. On the Exchanges page, find the exchange and click Details in the Actions column.

  2. In the upper-right corner of the Exchange Details page, click Send Message.

  3. In the Send Message panel, enter the Routing Key, select a value for mandatory (true or false), enter the Message ID and Message Body, then click OK.

View exchange statistics

View exchange metrics to monitor message routing and identify issues.

  1. On the Exchanges page, find the exchange and click Details in the Actions column.

  2. On the Exchange Details page, click the Dashboard tab.

The available metrics depend on your instance edition:

Instance edition

Monitoring source

Details

Enterprise Edition, Enterprise Platinum Edition

Managed Service for Prometheus and Managed Service for Grafana

See Dashboard.

Professional Edition, Standard Edition

CloudMonitor

See Monitoring and alerting.

Note

Standard Edition instances are no longer available for purchase. Existing Standard Edition instances remain functional.

Delete an exchange

Warning
  • After you delete an exchange, producers can no longer send messages to the exchange, and the exchange can no longer route messages to one or more queues or discard messages. Proceed with caution.

  • Exchanges of the headers type cannot be deleted.

  • Built-in vhost exchanges (amq.direct, amq.topic, amq.fanout, amq.headers, and amq.match) cannot be deleted.

  1. On the Exchanges page, click the name of the exchange to delete.

  2. In the upper-right corner of the Exchange Details page, click Delete.

  3. In the Note confirmation dialog, click OK.

References

For more information about exchange concepts and architecture, see Exchange.