Things about WebSocket (6- RabbitMQ STOMP destination detailed explanation)

1. Destination type

In the previous section about WebSocket (5-Spring STOMP support for connecting to external message brokers), we have briefly introduced various destination types, as shown below:
Insert image description here
In this section, we will discuss the differences between various destination types in detail.

The format of the request header in MESSAGEthe message destinationis as follows:

  • The destination format of messages published to the default switch is: /queue/queue_name.
  • amp.topicThe destination format of messages published to the switch is: topic/routing_key.
  • The format for all other message destinations is: /exchange/exchange_name/routing_key.

If the queue name, switch name, routing key contains /or characters, these characters will be replaced by , which %means hexadecimal encoding.非ascii%dddd


2. Exchange type destination

Any exchange/queue or exchange/routing-key combination can be /exchangeaccessed through a destination prefixed with .

For the SUBSCRIBE command, the destination format is: /exchange/<name>[/<pattern>], and the format description is as follows:

  • nameCreate an exclusive, automatically deleted queue on the switch .
  • If <pattern>specified <pattern>, the routing key is bound to namethe switch named.

For the SEND command, the destination format is: /exchange/<name>[/<routing-key>], and the format description is as follows:

  • By <routing-key>sending a message to namethe switch named.

Note: Exchange type destinations are not suitable for consuming information from existing queues. For each subscriber, a new queue is created and bound to the specified switch through the specified routing key. If you want to consume messages from an existing queue, you can use /amq/queuea destination.


3. Queue type destination

For simple queues, the destination format is /queue/<name>.

The Queue type destination will only deliver the message to at most one subscriber. If no consumer subscribes, the sent message will remain in the queue until the subscriber consumes it.

  • For the SUBSCRIBE command, this type of destination creates a shared namequeue named.
  • For the SEND command, a shared queue named namewill be created the first time a message is sent to a destination of this type, and the message will be namesent to the default switch based on the routing key.

4. AMQ Queue type destination

If you want to send or subscribe to a message from an existing queue that is not managed by the STOMP adapter, the message destination format is as /amq/queue/<name>follows:

  • For SEND and SUBSCRIBE commands, no queue is created. If the queue cannot exist, an error will be reported when using the SUBSCRIBE queue.
  • For the SEND command, the message will be sent directly nameto the existing queue named via the default switch.
  • For the SUBSCRIBE command, a subscription to the existing namequeue named will be established based on the current STOMP session.

Note: If no queue parameters are specified, the queue will be considered durable, non-exclusive, and non-automatically deleted.


5. Topic type destinations

The most commonly used destination type by STOMP clients is that /topic/<name>this type of destination can route messages to multiple subscribers. Messages sent to Topic type destinations will be discarded if no subscribers subscribe.

The format description of Topic type destination is as follows:

  • For the SEND command, the message will <name>be sent to amp.topicthe switch through the routing key.
  • For the SUBSCRIBE command, an automatically deleted and non-persistent queue is first created, and then the queue is <name>bound to amp.topicthe switch through the routing key.

stomp.default_topic_exchangeThe name of the default Topic switch can be modified through parameters, as follows:

stomp.default_topic_exchange = some.exchange

For more instructions on destination types, please refer to: RabbitMQ STOMP plug-in instructions .

Insert image description here

Guess you like

Origin blog.csdn.net/lingbomanbu_lyl/article/details/133091785