Updated on 2024-10-25 GMT+08:00

Binding a RabbitMQ Exchange

Binding an exchange is to relate an exchange to another exchange or queue. In this way, producers send messages to exchanges and exchanges route these messages to related exchanges or queues.

This section describes how to bind exchanges on the console. An exchange can be bound with a target exchange or a queue can be bound with a source exchange. An exchange can be bound with multiple target exchanges. A queue can be bound with multiple source exchanges.

Notes and Constraints

  • In RabbitMQ 3.x.x, the exchange (AMQP default) cannot be bound with any exchange.
  • In RabbitMQ AMQP-0-9-1, exchanges can only be bound with queues and not exchanges.
  • Internal exchanges can only be bound with exchanges and not queues.

Prerequisites

An exchange has been created.

Binding an Exchange to a Target Exchange

  1. Log in to the console.
  2. In the upper left corner, click and select a region.

    Select the region where your RabbitMQ instance is.

  3. Click and choose Middleware > Distributed Message Service for RabbitMQ to open the console of DMS for RabbitMQ.
  4. Click an instance name to go to the instance details page.
  5. In the navigation pane, choose Virtual Hosts.
  6. Click a virtual host name.
  7. On the Exchange tab page, click Bind Exchange in the row containing the desired exchange. The Bind Exchange page is displayed.
  8. Click Add Binding. The Add Binding dialog box is displayed.
  9. Set the parameters by referring to Table 1.

    Table 1 Binding parameters

    Parameter

    Description

    Type

    This parameter is only available in RabbitMQ 3.x.x. RabbitMQ AMQP-0-9-1 supports only queue bindings.

    Select the binding type: Select Exchange.

    Target

    Select a target exchange to be bound.

    Routing Key

    Enter a key string to inform the exchange of which target exchanges to deliver messages to.

    • This parameter is required by direct exchanges and topic exchanges. Such exchanges route messages to target exchanges with the routing keys matched. If this parameter is not set, exchanges route messages to all the bound target exchanges.
    • Enabling x-consistent-hash exchanges requires a routing key which indicates the weight of a queue. The larger the key, the heavier the weight, which means that the queue receives more messages.
    • For fanout exchanges and header exchanges, skip this parameter.

  10. Click OK.

    On the Bindings page, view the bound exchange.

Binding Source Exchanges to a Queue

  1. Log in to the console.
  2. In the upper left corner, click and select a region.

    Select the region where your RabbitMQ instance is.

  3. Click and choose Middleware > Distributed Message Service for RabbitMQ to open the console of DMS for RabbitMQ.
  4. Click an instance name to go to the instance details page.
  5. In the navigation pane, choose Virtual Hosts.
  6. Click a virtual host name.
  7. On the Queue tab page, click View Detail in the row containing the desired queue.
  8. On the Bindings tab, click Add Binding. The Add Binding dialog box is displayed.
  9. Set the parameters by referring to Table 2.

    Table 2 Binding parameters

    Parameter

    Description

    Source

    Select an exchange to be bound.

    Routing Key

    Enter a key string to inform the exchange of which queues to deliver messages to.

    • This parameter is required by direct exchanges and topic exchanges. Such exchanges route messages to queues with the routing keys matched. If this parameter is not set, exchanges route messages to all the bound queues.
    • Enabling x-consistent-hash exchanges requires a routing key which indicates the weight of a queue. The larger the key, the heavier the weight, which means that the queue receives more messages.
    • For fanout exchanges and header exchanges, skip this parameter.

  10. Click OK.

    On the Bindings tab, view the new exchange.