Distributed Message Service RabbitMQ

Exchange Management

2024-06-27 06:36:31

Background

The producer sends the message to the exchange, which routes the message to one or more queues (or discards them). The exchange routes messages to the queue based on the Routing Key and Binding Key. The routing rules vary for different types of exchanges.

Create an Exchange

(1) Log in to the management console.

(2) Go to the RabbitMQ console.

(3) In the operation column of the instance list page, click Manage in the target instance row.

(4) Click Exchange Management, then click the New button.

(5) Click New and the following window will appear, select the Vhost, add the exchange name, select the exchange type and other parameters, then click OK to create a new exchange.

Parameter

Description

Virtual Host

Select the virtual host to which the exchange is created

Name

The   name of the exchange. Fields starting with amq. are reserved fields and   cannot be used. For example: amq.test.

Type

Exchange   type. Value:

direct:   This type of routing rule will route the message to the Queue whose Binding   key exactly matches the Routing key.

topic:   This type is similar to direct. Topic Exchange routing rules are not as   strict as Direct Exchange and support fuzzy matching and multi-criteria   matching, i.e., this type of Exchange uses Routing Key pattern matching and   string comparison to route messages to the bound Queue.

fanout:   This type of routing rule is very simple, it will route all messages sent to   the Exchange to all queues bound to it, which is equivalent to the broadcast   function.

headers:   This type is similar to direct. Headers Exchange uses the Headers attribute   instead of Routing Key for routing matching. When binding Headers Exchange   and Queue, set the key-value pair of the binding attribute. When sending a   message to Headers Exchange, set the Headers attribute key-value pair of the   message, and route the message to the bound Queue by comparing the message   Headers attribute key-value pair with the binding attribute key-value pair.

x-delayed-message:   By declaring this type of Exchange, you can customize the Header attribute   x-delay of the message to specify the time period for delayed message   delivery, in milliseconds. Messages will be delivered to the corresponding   queue based on the routing rules after the time period specified in x-delay.   The routing rules depend on the Exchange routing type specified in x-delayed-type.

x-delayed-type

When   the Exchange type is x-delayed-message, you need to configure this parameter   to specify the routing type of Exchange.

Persistence   or Not

Whether   the exchange is persisted to disk

Whether   to delete automatically

If so,   the exchange will be deleted when at least one queue or exchange is bound to   it and then all queues or exchanges have been unbound.

Built-in   or Not

If so,   the client cannot publish directly to this exchange. It can only be used in   conjunction with other exchanges.

Other   Parameters

Alternate exchange: The backup exchange is to implement messages   that are not routed to the queue. When declaring the exchange, add the   attribute alternate-exchange and declare an alternate exchange. Generally, it   is declared as fanout type, so that messages received by the exchange that   are not routed to the queue will be sent to the queue bound to the alternate   exchange.

 

Parameter

Description

Virtual Host

Select the virtual host to which the exchange is created

Name

The   name of the exchange. Fields starting with amq. are reserved fields and   cannot be used. For example: amq.test.

Type

Exchange   type. Value:

x-delayed-type

When   the Exchange type is x-delayed-message, you need to configure this parameter   to specify the routing type of Exchange.

Persistence   or Not

Whether   the exchange is persisted to disk

Whether   to delete automatically

If so,   the exchange will be deleted when at least one queue or exchange is bound to   it and then all queues or exchanges have been unbound.

Built-in   or Not

If so,   the client cannot publish directly to this exchange. It can only be used in   conjunction with other exchanges.

Other   Parameters

Alternate exchange: The backup exchange is to implement messages   that are not routed to the queue. When declaring the exchange, add the   attribute alternate-exchange and declare an alternate exchange. Generally, it   is declared as fanout type, so that messages received by the exchange that   are not routed to the queue will be sent to the queue bound to the alternate   exchange.


View Exchange

(6) Click on the target exchange name to view the exchange overview.

(7) Click Binding Information to view the binding information of the exchange.

(8) Click Bound Information to view the bound information of the exchange.

Delete Exchange

(9) Click Delete on the target exchange to delete the exchange.


Qr5jJPlb4mY8