Topic Patterns
Topics are used to classify and filter different MQTT messages. To achieve this goal, users need to follow and understand MQTT topic patterns.
Topic Structures
This is how a typical topic would look like on the STS-MQTT server. As you can see, topics has different levels, and each level is seperated by “/”. On STS-MQTT, all topics start with users, and followed by the username of the topic owner.
A topic may have many different levels for organizing messages. As you can see in the above sample topic, user can set different levels for better organization of messages sent to the server. You can treat mqtt topics as channels for communication.
Topic Level Wildcard
Users can use wildcard symbol to represent all topics at specific levels.
Single Level Using +
Users can use the plus sign in the topic to represent wildcard for one level. In this case, any topic with arbitrary string would match the level that contains the plus sign. For example, users/tom/+/data
would match the following:
users/tom/temperature/data
users/tom/humidity/data
but not the following:
users/tom/temperature
users/tom/data/humidity
Multi Levels Using #
Users can use the hashtag to represent multi levels. In this case, any topic with arbitrary string in arbitrary levels would match the level that contains the hashtag sign. Note that the hashtag symbol can only be presented at the end of a topic string. For example, users/tom/temperature/#
would match the following:
users/tom/temperature/data
users/tom/temperature/timestamp
users/tom/temperature/quality
but not the following:
users/tom/humidity/data
users/tom/light/data
Note: Currently, you can only use wildcard symbol on your own topics, i.e. you cannot use wildcard symbol to subscribe or publish to topics owned by other users.