Table of contents
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:
In this section, we will discuss the differences between various destination types in detail.
The format of the request header in MESSAGE
the message destination
is as follows:
- The destination format of messages published to the default switch is:
/queue/queue_name
. amp.topic
The 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
%dd
dd
2. Exchange type destination
Any exchange/queue or exchange/routing-key combination can be /exchange
accessed through a destination prefixed with .
For the SUBSCRIBE command, the destination format is: /exchange/<name>[/<pattern>]
, and the format description is as follows:
name
Create an exclusive, automatically deleted queue on the switch .- If
<pattern>
specified<pattern>
, the routing key is bound toname
the 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 toname
the 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/queue
a 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
name
queue named. - For the SEND command, a shared queue named
name
will be created the first time a message is sent to a destination of this type, and the message will bename
sent 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
name
to the existing queue named via the default switch. - For the SUBSCRIBE command, a subscription to the existing
name
queue 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 toamp.topic
the 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 toamp.topic
the switch through the routing key.
stomp.default_topic_exchange
The 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 .