Basics of MQTT topic matching rules
1. Subject level separator—"/":
Used to divide the topic level, / topic after division, this is a very important symbol in the message topic hierarchy design
eg: aaaa/bbbb and aaaa/bbbb/cccc and aaaa/bbbb/cccc/dddd, this message topic format is a progressive relationship, which can match both at the same time through multi-level wildcards, or single-level wildcards only Match one. In real scenarios, this can be applied to: company department-level push, national city-level push and other scenes that contain hierarchical relationships.
2. Single-level wildcard—-"+":
Single-level wildcards can only match one level of themes. eg: aaaa/+ can match aaaa/bbbb, but cannot match aaaa/bbbb/cccc. A single + sign can match all pushes of a single layer
3. Multi-layer wildcard —-"#":
#: Multi-layer wildcard, multi-layer wildcard can match multi-layer themes. For example: aaaa/# can not only match aaaa/bbbb, but also aaaa/bbbb/cccc/dddd. In other words, multi-level wildcards can match all subset topics that match the topic level before the wildcard. The single # matches all message subjects.
4. Wildcard —-"$":
The wildcard "$" means to match a character, as long as it is not placed at the very beginning of the subject, that is:
$xx/$xx/xx$
In other cases, it means to match a character.
If the client wants to receive messages with a topic starting with "SYS/" and messages with a topic not starting at the same time, it needs to subscribe to "#" and ""$SYS/#" at the same time.
5.Summary:
a. All topic names and topic filters must contain at least one character
b. Subject names or subject filters are distinguished by a leading or trailing slash "/"
c. The subject name or subject filter that only contains the slash "/" is legal
d. The subject name and subject filter are UTF-8 encoded strings, and they cannot exceed 65535 bytes
e. Subject names and subject filters are case sensitive
f. Single-level wildcards and multi-level wildcards can only be used to subscribe to (subscribe) messages but not to publish (publish) messages. The level separator can be used in both cases