An exchange is used to route a message received from a producer to one or more queues or discard the message. This topic describes how to create an exchange in the Message Queue for RabbitMQ console.
- Log on to the Message Queue for RabbitMQ console.
- In the Resource Distribution section of the Overview page, select the region where your instance is located.
- On the Instances page, click the name of your instance.
- In the left-side navigation pane, click Exchanges.
- 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.
- In the Create Exchange panel, set Exchange Name, Type, and Internal. Then, click OK.
Parameter Description Exchange Name The name of the exchange. The name of an exchange cannot start with amq. because amq. is used as a reserved field. For example, amq.test is an invalid name. Type The type of the exchange. Valid values:
- direct: An exchange of this type routes a message to the queue whose binding key exactly matches the routing key of the message.
- topic: This type is similar to the direct exchange type. However, the routing rule for a topic exchange is less demanding than that 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 the queues bound to this exchange. You can use a fanout exchange to broadcast messages.
- headers: This type is similar to the direct exchange type. The only difference is that a headers exchange routes messages based on headers attributes instead of routing keys. When you bind a headers exchange to a queue, you must configure binding attributes in the key-value format for the binding. When you send a message to a headers exchange, you must configure headers attributes in the key-value format for the message. After a headers exchange receives a message, it routes the message based on the matching between the headers attributes of the message and binding attributes of the bound queues.
- x-jms-topic: This type applies to Java Message Service (JMS) applications that access Message Queue for RabbitMQ by using the JMS API provided by Message Queue for RabbitMQ. This type of exchange 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 will be delivered. The period of time is in milliseconds. The message will be delivered to the corresponding queue after the period of time specified by the x-delay header attribute elapses. The exchange routes messages based on the routing rule that corresponds to the exchange type specified by x-delayed-type.
x-delayed-type If the exchange type is x-delayed-message, you must set this parameter to specify the routing rule for the exchange. 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.