Bird
Raised Fist0
IOT Protocolsdevops~10 mins

Topics and topic hierarchy in IOT Protocols - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Topics and topic hierarchy
Start: Client wants to send message
↓
Choose Topic: e.g. home/kitchen/temperature
↓
Publish message to topic
↓
Broker receives message
↓
Broker forwards message to subscribers
↓
Subscribers receive message if subscribed to topic or matching wildcard
↓
End
This flow shows how a client picks a topic, publishes a message, and how the broker routes it to subscribers based on topic hierarchy.
Execution Sample
IOT Protocols
Publish to topic: home/kitchen/temperature
Subscriber A subscribes to: home/kitchen/#
Subscriber B subscribes to: home/+/temperature
Publish message: 22°C
A message with temperature data is published to a specific topic; subscribers receive it if their subscriptions match the topic hierarchy.
Process Table
StepActionTopic UsedSubscriber Subscribed ToMessage Received
1Client publishes messagehome/kitchen/temperature--
2Broker checks subscribershome/kitchen/temperatureSubscriber A: home/kitchen/#Yes
3Broker checks subscribershome/kitchen/temperatureSubscriber B: home/+/temperatureYes
4Broker delivers message to Subscriber Ahome/kitchen/temperaturehome/kitchen/#22°C
5Broker delivers message to Subscriber Bhome/kitchen/temperaturehome/+/temperature22°C
6No other subscribers match---
💡 All matching subscribers received the message; no more matches found.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Published Topic-home/kitchen/temperaturehome/kitchen/temperaturehome/kitchen/temperaturehome/kitchen/temperature
Message-22°C22°C22°C22°C
Subscriber A Subscriptionhome/kitchen/#home/kitchen/#home/kitchen/#home/kitchen/#home/kitchen/#
Subscriber B Subscriptionhome/+/temperaturehome/+/temperaturehome/+/temperaturehome/+/temperaturehome/+/temperature
Message Delivered to ANoNoYesYesYes
Message Delivered to BNoNoNoYesYes
Key Moments - 3 Insights
Why does Subscriber A receive the message when subscribed to home/kitchen/#?
Because the '#' wildcard matches any subtopic after home/kitchen/, so home/kitchen/temperature fits this pattern (see execution_table step 2 and 4).
Why does Subscriber B receive the message when subscribed to home/+/temperature?
The '+' wildcard matches exactly one level, so home/+/temperature matches home/kitchen/temperature (see execution_table step 3 and 5).
What happens if a subscriber subscribes to home/kitchen only?
They will only receive messages published exactly to home/kitchen, not to subtopics like home/kitchen/temperature (not shown in current table but implied by topic hierarchy).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which subscriber receives the message at step 5?
ASubscriber A
BBoth Subscriber A and B
CSubscriber B
DNo subscriber
💡 Hint
Check the 'Message Received' column at step 5 in the execution_table.
At which step does the broker check Subscriber A's subscription?
AStep 1
BStep 2
CStep 4
DStep 6
💡 Hint
Look at the 'Subscriber Subscribed To' column in the execution_table for Subscriber A.
If Subscriber B changed subscription to home/kitchen/temperature, what would happen?
ASubscriber B would receive the message only if published to home/kitchen/temperature
BSubscriber B would not receive the message
CSubscriber B would receive all messages under home/#
DSubscriber B would receive no messages
💡 Hint
Refer to how exact topic matches work in the variable_tracker and execution_table.
Concept Snapshot
Topics in IoT protocols are like addresses for messages.
They use slashes '/' to separate levels, like folders.
Wildcards '+' (one level) and '#' (multiple levels) help subscribe to many topics.
Messages published to a topic go to all subscribers matching that topic or wildcard.
Understanding topic hierarchy helps control message flow efficiently.
Full Transcript
This visual execution shows how messages are sent and received using topics and topic hierarchy in IoT protocols. A client publishes a message to a topic like home/kitchen/temperature. The broker checks all subscribers to see whose subscriptions match this topic. Subscribers can use wildcards like '#' to match multiple subtopics or '+' to match exactly one level. Subscribers with matching subscriptions receive the message. The execution table tracks each step, showing which subscribers get the message and why. The variable tracker shows how topics, messages, and subscriptions change during the process. Key moments clarify why wildcards work and how exact matches differ. The quiz tests understanding of subscriber message delivery and topic matching. The snapshot summarizes the main ideas about topic hierarchy and wildcards for quick recall.

Practice

(1/5)
1. What is the main purpose of topics in IoT protocols like MQTT?
easy
A. To encrypt messages for security
B. To store device firmware
C. To organize messages in a clear, folder-like structure
D. To control device power settings

Solution

  1. Step 1: Understand the role of topics

    Topics act like folders to organize messages so devices know where to send or receive data.
  2. Step 2: Compare options with topic function

    Only organizing messages matches the purpose of topics; encryption and firmware storage are unrelated.
  3. Final Answer:

    To organize messages in a clear, folder-like structure -> Option C
  4. Quick Check:

    Topics organize messages = B [OK]
Hint: Topics are like folders for messages [OK]
Common Mistakes:
  • Confusing topics with security features
  • Thinking topics store device data
  • Mixing topics with device settings
2. Which of the following is the correct way to write a topic with three levels?
easy
A. home-kitchen-temperature
B. home.kitchen.temperature
C. home\kitchen\temperature
D. home/kitchen/temperature

Solution

  1. Step 1: Recall topic level separator

    Topics use slashes (/) to separate levels, like folders in a path.
  2. Step 2: Check each option's separator

    Only home/kitchen/temperature uses slashes correctly; others use dots, backslashes, or dashes which are incorrect.
  3. Final Answer:

    home/kitchen/temperature -> Option D
  4. Quick Check:

    Topic levels separated by '/' = A [OK]
Hint: Use slashes (/) to separate topic levels [OK]
Common Mistakes:
  • Using dots instead of slashes
  • Using backslashes which are invalid
  • Using dashes instead of separators
3. Given the topic building1/floor2/room3/sensor, which part represents the third level?
medium
A. room3
B. floor2
C. building1
D. sensor

Solution

  1. Step 1: Split the topic by slashes

    Splitting 'building1/floor2/room3/sensor' by '/' gives ['building1', 'floor2', 'room3', 'sensor'].
  2. Step 2: Identify the third element

    The third element (index 2) is 'room3'.
  3. Final Answer:

    room3 -> Option A
  4. Quick Check:

    Third level = room3 = C [OK]
Hint: Count levels separated by '/' to find position [OK]
Common Mistakes:
  • Counting from zero incorrectly
  • Choosing first or second level by mistake
  • Confusing last level with third
4. Identify the error in this topic string: home//livingroom/temperature
medium
A. Double slash creates an empty level
B. Missing slash between 'home' and 'livingroom'
C. Topic levels must use dots, not slashes
D. Topic cannot contain the word 'temperature'

Solution

  1. Step 1: Analyze the topic string

    The string 'home//livingroom/temperature' has two slashes together, meaning an empty level between them.
  2. Step 2: Understand topic level rules

    Empty levels are invalid because each level should have a name; double slashes cause this error.
  3. Final Answer:

    Double slash creates an empty level -> Option A
  4. Quick Check:

    Double slash = empty level error = A [OK]
Hint: Avoid double slashes to prevent empty topic levels [OK]
Common Mistakes:
  • Ignoring empty levels caused by double slashes
  • Thinking dots are required separators
  • Believing certain words are forbidden in topics
5. You want to subscribe to all sensors in any room on floor 1 of building 2 using MQTT topics. Which subscription topic should you use?
hard
A. building2/floor1/*/sensor
B. building2/floor1/+/sensor
C. building2/floor1/room1/sensor
D. building2/floor1/#/sensor

Solution

  1. Step 1: Understand MQTT wildcards

    The '+' wildcard matches exactly one level, while '#' matches all remaining levels.
  2. Step 2: Analyze the subscription needs

    We want any room on floor1, so '+' replaces the room level. '#' would match too many levels, and '*' is invalid in MQTT.
  3. Final Answer:

    building2/floor1/+/sensor -> Option B
  4. Quick Check:

    '+' wildcard for one level = D [OK]
Hint: Use '+' for single-level wildcard in MQTT topics [OK]
Common Mistakes:
  • Using '#' when only one level is needed
  • Using '*' which is not a valid MQTT wildcard
  • Specifying exact room instead of wildcard
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard