0
0
IOT Protocolsdevops~10 mins

Wildcard subscriptions (+ and #) in IOT Protocols - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Wildcard subscriptions (+ and #)
Start Subscription
Check Topic Filter
Match Single Level
| No
Match Multi Level
No
Exact Match
Deliver Messages
This flow shows how MQTT wildcard subscriptions use '+' to match one topic level and '#' to match multiple levels, deciding which messages to deliver.
Execution Sample
IOT Protocols
Subscribe to: sensors/+/temperature
Publish to: sensors/livingroom/temperature
Publish to: sensors/kitchen/humidity
Subscribe with '+' wildcard to receive temperature from any room, then publish messages to different topics to see which match.
Process Table
StepSubscription Topic FilterPublished TopicMatch ConditionMatch ResultMessage Delivered
1sensors/+/temperaturesensors/livingroom/temperature'+' matches 'livingroom' levelMatchYes
2sensors/+/temperaturesensors/kitchen/humidity'temperature' != 'humidity' at last levelNo MatchNo
3sensors/#sensors/kitchen/humidity'#' matches all remaining levelsMatchYes
4sensors/#devices/kitchen/humidityFirst level 'sensors' != 'devices'No MatchNo
5home/+/temperaturehome/livingroom/temperature'+' matches 'livingroom'MatchYes
6home/+/temperaturehome/livingroom/kitchen/temperature'+' matches only one level, extra levels presentNo MatchNo
💡 All published topics checked against subscription filters; messages delivered only if match conditions met.
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6Final
Subscription Topic Filtersensors/+/temperaturesensors/+/temperaturesensors/+/temperaturesensors/#sensors/#home/+/temperaturehome/+/temperaturehome/+/temperature
Published Topicsensors/livingroom/temperaturesensors/kitchen/humiditysensors/kitchen/humiditydevices/kitchen/humiditydevices/kitchen/humidityhome/livingroom/temperaturehome/livingroom/kitchen/temperaturehome/livingroom/kitchen/temperature
Match ResultMatchNo MatchMatchNo MatchNo MatchMatchNo MatchNo Match
Message DeliveredYesNoYesNoNoYesNoNo
Key Moments - 3 Insights
Why does '+' only match one level and not multiple levels?
The '+' wildcard matches exactly one topic level. For example, in row 6 of the execution table, 'home/+/temperature' does not match 'home/livingroom/kitchen/temperature' because '+' matches only 'livingroom', not multiple levels like 'livingroom/kitchen'.
How does '#' differ from '+' in matching topics?
The '#' wildcard matches zero or more levels at the end of the topic. For example, in row 3, 'sensors/#' matches 'sensors/kitchen/humidity' because '#' covers all remaining levels after 'sensors'.
Can '#' be used in the middle of a topic filter?
No, '#' must be the last character in the topic filter. It matches all remaining levels from that point. This is why in the examples, '#' appears only at the end.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at step 2, why is the message not delivered?
ABecause '+' does not match 'kitchen'
BBecause the last level 'humidity' does not match 'temperature'
CBecause '#' wildcard is missing
DBecause the published topic has too many levels
💡 Hint
Check the 'Match Result' and 'Match Condition' columns at step 2 in the execution table.
At which step does the '#' wildcard allow matching multiple topic levels?
AStep 3
BStep 1
CStep 5
DStep 6
💡 Hint
Look for '#' in the 'Subscription Topic Filter' column and see where it matches multiple levels.
If the subscription was 'home/#' instead of 'home/+/temperature', which published topic would match at step 6?
Asensors/livingroom/temperature
Bhome/livingroom/temperature
Chome/livingroom/kitchen/temperature
Ddevices/kitchen/humidity
💡 Hint
Refer to how '#' matches multiple levels in the variable_tracker and execution_table.
Concept Snapshot
MQTT wildcard subscriptions:
- '+' matches exactly one topic level
- '#' matches zero or more levels at the end
- '+' and '#' help subscribe to multiple topics easily
- '#' must be last in filter
- Messages delivered only if topic matches filter
Full Transcript
This lesson shows how MQTT wildcard subscriptions work using '+' and '#'. The '+' wildcard matches exactly one level in the topic path, like a single folder in a file path. The '#' wildcard matches all remaining levels, like a catch-all folder. We traced examples where subscriptions with '+' matched topics with one varying level, and '#' matched multiple levels. We saw why some messages are delivered and others are not, based on these rules. This helps understand how to subscribe to many topics efficiently in IoT messaging.