This topic describes how to create an exchange, view the statistics of an exchange, bind an exchange to a queue, bind an exchange to another exchange, and send the messages in an exchange to a bound queue in the Message Queue for RabbitMQ console.

Background information

An exchange is used to route a message received from a producer to one or more queues or to discard the message. The exchange routes a message to queues by using the routing key and binding keys. Different routing rules are used for different types of exchanges. For more information, see Exchanges.

Create an exchange

  1. Log on to the Message Queue for RabbitMQ console. In the left-side navigation pane, select Instances.
  2. In the top navigation bar of the Instances page, select a region. In the instance list, click the name of the instance that you want to manage.
  3. In the left-side navigation pane, click Exchanges.
  4. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost in which you want to create an exchange. Then, click Create Exchange.
  5. In the Create Exchange panel, configure the Exchange Name, Type, and Internal parameters. Then, click OK. The following table describes these parameters.
    Parameter Description
    Exchange Name The name of the exchange. A name that starts with amq. is used as a reserved field and cannot be used in an exchange name. For example, you cannot use amq.test as the name of an exchange.
    Type The type of the exchange. Valid values:
    • direct: An exchange of this type routes a message to the queue whose binding key is the same as the routing key of the message.
    • topic: An exchange of this type is similar to an exchange of the direct type. However, the routing rule for a topic exchange is less demanding than the routing rule for a direct exchange. A topic exchange routes a message to one or more bound queues based on the result of fuzzy match or multi-condition match between the routing key of the message and the binding keys that are used to bind the queues to the exchange.
    • fanout: An exchange of this type routes all the received messages to all queues that are bound to this exchange. The working mechanism of a fanout exchange is similar to the broadcasting feature.
    • headers: An exchange of this type is similar to an exchange of the direct type. The only difference between a headers exchange and a direct exchange is that a headers exchange routes messages based on the headers attributes instead of routing keys. When you bind a headers exchange to a queue, configure binding attributes in the key-value format. When you send a message to a headers exchange, configure the headers attributes in the key-value format for the message. After a headers exchange receives a message, the exchange routes the message based on the matching results between the headers attributes of the message and the binding attributes of the bound queues.
    • x-jms-topic: Exchanges of this type are suitable for Java Message Service (JMS) applications that access Message Queue for RabbitMQ by using the JMS API provided by Message Queue for RabbitMQ. An exchange of this type routes a message to queues based on the result of fuzzy match between the routing key and binding keys. Wildcards are used to support fuzzy match. For more information, see Overview.
    • x-delayed-message: You can declare an exchange of this type and set the x-delay header attribute of a message to specify the period of time after which the message is sent. The period of time is in milliseconds. The message is sent to the corresponding queue after the period of time specified by the x-delay header attribute is elapsed. The exchange routes messages based on the routing rule that corresponds to the exchange type specified by x-delayed-type.
    • x-consistent-hash : An exchange of the x-consistent-hash type allows you to perform hash calculation on routing keys or header values and use consistent hashing to route a message to different queues.
    x-delayed-type If you set the Type parameter to x-delayed-message, you must configure this parameter to specify the routing rule for the exchange.
    Hash value If you set the Type parameter to x-consistent-hash, you must configure this parameter to specify the type of the input value for hash calculation. Valid values:
    • RoutingKey
    • Header Value: If you use headers as the input value for hash calculation, you must specify the value for the hash-header parameter.
    hash-header If you set the Type parameter to x-consistent-hash and the Hash value parameter to Header Value, you must configure this parameter as the input value for hash calculation.
    Internal Specifies whether the exchange is an internal exchange. Default value: No. Valid values:
    • Yes: The exchange is bound to another exchange.
    • No: The exchange is bound to a queue.

View statistics of an exchange

You can view various metric data to identify and locate problems at the earliest opportunity.

  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost of the exchange that you want to view. Then, find the exchange.
  2. You can view statistics of the exchange based on your business requirements.
    • View statistics of the exchange: Click the exchange, or click Details in the Actions column. On the Exchange Details page, click the Dashboard tab.
    • View statistics of the exchange, such as vhost, and instance statistics: In the Actions column of the exchange, click Dashboard.

      You can also click the exchange name, or click Details in the Actions column of the exchange. In the upper-right corner of the Exchange Details page, click Dashboard.

    The statistics of the exchange vary based on the instance edition. The following list describes the statistics of various instance editions.

    • Basic Edition and Professional Edition: CloudMonitor is used to provide metric monitoring data. For more information about metrics provided by CloudMonitor, see Monitoring and alerting.
      Note Message Queue for RabbitMQ instances of the Basic Edition and Professional Edition are deprecated. You can continue to use the purchased instances of the Basic Edition.
    • Enterprise Edition and Platinum Edition: You can view metrics provided by Application Real-Time Monitoring Service (ARMS) Prometheus Service and Grafana. For more information about the dashboard and metrics, see Dashboard.

Bind an exchange to a queue

You can bind an exchange to a queue to determine the queue to which the exchange routes messages.

  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost of the exchange that you want to bind to a queue. 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, select Queue for the Type of Destination to Bind parameter, select a queue from the Destination to Bind drop-down list, configure the Binding Key parameter, and then click OK.
    Note
    • If the type of the bound exchange is x-consistent-hash, the Routing Key parameter indicates the weight of the queue to which the exchange is bound. The value of the Routing Key parameter can be an integer from 1 to 20.
    • If an exchange is bound to a queue multiple times, only the first binding that meets the conditions takes effect.
    • To change the weight of the queue to which an exchange is bound, you must delete the existing binding before you add the new binding.
    Add a binding

Create an exchange-to-exchange binding whose source is a specific exchange

Create a binding whose source is a specific exchange to allow messages to be forwarded from the source exchange to an exchange based on routing rules.

  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost of the exchange for which you want to create an exchange-to-exchange binding. 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, select Exchange for Type of Destination to Bind, select an exchange from the Destination to Bind drop-down list, configure Binding Key, and then click OK.
    Create an exchange-to-exchange binding whose source is a specific exchange

Create a binding whose destination is a specific exchange

Create a binding whose destination is a specific exchange to allow messages to be forwarded from an exchange to the destination exchange based on routing rules.

  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost of the exchange for which you want to create an exchange-to-exchange binding. Find the exchange, and choose More > Bound as Destination in the Actions column.
  2. On the Exchange Details page, choose the Bound as Destination tab and click Add Binding.
  3. In the Add Binding panel, select an exchange from the Source Exchange drop-down list, enter a binding key in the Binding Key field, use the default values for Type of Destination to Bind and Destination Exchange, and then click OK.
    Create an exchange-to-exchange binding whose destination is a specific exchange

Send a message

After you add a binding to an exchange, you can send a message in the exchange to the queue to which the exchange is bound or send a message from the bound exchange to the source exchange in the Message Queue for MQTT console.

  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost of the exchange that you want to manage. Then, find the exchange.
  2. On the Exchange Details page, click the Bound as Source tab or the Bound as Destination tab.
  3. In the Bound as Source or Bound as Destination list, select the specified binding relationship and click Send Message in the Actions column.
  4. In the Send Message panel that appears, configure messageId and messageBody, and click OK.

Delete exchanges

Warning
  • After you delete a specific exchange, producers can no longer send messages to the exchange or route the exchange to one or more queues. Proceed with caution.
  • You cannot delete exchanges of the headers and x-jms-topic types.
  • You cannot delete the built-in exchanges in a vhost. These exchanges are amq.direct, amq.topic, and amq.fanout.
  1. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost from which you want to delete one or more exchanges. Then, delete exchanges by using one of the following methods:
    • To delete a single exchange, find the exchange that you want to delete, and choose More > Delete in the Actions column.

      You can also click the name of the exchange that you want to delete or click Details in the Actions column of the exchange. Then, click Delete in the upper-right corner of the Exchange Details page.

    • Delete multiple exchanges: Select the exchanges that you want to delete and click Batch Delete below the exchange list.
  2. Read the Note message that appears and click OK.
    On the Exchanges page, you can no longer view the exchanges that you deleted.