In the above picture, three subscribers subscribe to the same topic using a shared subscription method, where topic
is the real topic name they subscribed to, and is a shared subscription Prefix. EMQX Broker supports shared subscription prefixes in two formats:
Shared subscriptions prefixed with $ share/<group-name>
are shared subscriptions with groups:
For example, suppose that subscribers s1, s2, and s3 belong to group g1, and subscribers s4 and s5 belong to group g2. Then when EMQX Broker publishes a message msg1 to this topic:
- Only one of s1, s2, s3 will receive msg1
Shared subscriptions prefixed with are shared subscriptions without groups. It is a special case of $share
subscription, which is quite similar to all subscribers in a subscription group:
Balancing strategy | Description |
---|---|
hash_clientid | According to the hash value of the publisher ClientID |
hash_topic | According to the hash value of the message’s topic name |
local | Selects random subscriber connected to the node which received the message. If no such subscribers present, selects a random cluster-wise |
random | Select randomly among all subscribers |
round_robin | According to the order of subscription |
sticky | First dispatch is random, then stick to it for all subsequent messages until that subscriber goes disconnected or that publisher reconnects |
TIP
Whether it is a single client subscription or a shared subscription, pay attention to the client performance and message reception rate, otherwise it will cause errors such as message accumulation and client crash.