0
0
IOT Protocolsdevops~6 mins

Topics and topic hierarchy in IOT Protocols - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine you want to send messages to different groups of people based on their interests. Without a clear way to organize these groups, messages would get lost or sent to the wrong people. Topics and topic hierarchy solve this by organizing messages so they reach the right receivers efficiently.
Explanation
What is a Topic
A topic is like a label or a category name that messages are sent to or received from. It helps organize messages by subject so devices or applications can subscribe only to the topics they care about. Topics are simple text strings that describe the message content area.
A topic is a named channel that organizes messages by subject.
Topic Hierarchy Structure
Topics can be arranged in a hierarchy using slashes to separate levels, like folders in a file system. This allows grouping related topics under a common parent topic. For example, 'home/kitchen/temperature' and 'home/livingroom/temperature' share the 'home' parent topic.
Topic hierarchy organizes topics in levels separated by slashes for better grouping.
Wildcards in Topic Subscription
Wildcards let subscribers listen to multiple topics at once without listing each one. The single-level wildcard '+' matches one level in the hierarchy, while the multi-level wildcard '#' matches all remaining levels. This makes it easy to subscribe broadly or narrowly.
Wildcards allow flexible subscription to multiple topics in a hierarchy.
Benefits of Topic Hierarchy
Using a topic hierarchy helps keep messages organized and reduces unnecessary data traffic. Devices only receive messages relevant to their subscribed topics, improving efficiency and clarity in communication. It also simplifies managing large numbers of topics.
Topic hierarchy improves message organization and communication efficiency.
Real World Analogy

Think of a large library where books are organized by sections, shelves, and categories. If you want a book about cooking, you go to the 'Cooking' section, then to a specific shelf like 'Baking'. This way, you find books quickly without searching the entire library.

What is a Topic → A book section label like 'Cooking' that groups related books
Topic Hierarchy Structure → Shelves and subcategories within the library section, like 'Baking' under 'Cooking'
Wildcards in Topic Subscription → Choosing to browse all shelves in 'Cooking' or just one specific shelf
Benefits of Topic Hierarchy → Finding books faster and avoiding looking through unrelated sections
Diagram
Diagram
┌─────────┐
│  home   │
├─────────┤
│ kitchen │
│  │      │
│  ├─temperature
│  └─humidity
├─────────┤
│livingroom│
│  ├─temperature
│  └─humidity
└─────────┘
This diagram shows a topic hierarchy with 'home' as the root, branching into 'kitchen' and 'livingroom', each having 'temperature' and 'humidity' topics.
Key Facts
TopicA named string that categorizes messages for sending and receiving.
Topic HierarchyA structure of topics separated by slashes to organize messages in levels.
Single-level Wildcard (+)A symbol that matches exactly one level in a topic hierarchy.
Multi-level Wildcard (#)A symbol that matches any number of levels in a topic hierarchy.
SubscriptionThe act of registering to receive messages from specific topics.
Common Confusions
Believing topics are like message contents rather than labels.
Believing topics are like message contents rather than labels. Topics are labels or addresses for messages, not the message content itself.
Thinking wildcards can be used anywhere in the topic string.
Thinking wildcards can be used anywhere in the topic string. Wildcards must follow specific rules: '+' replaces one level, '#' must be last and replaces all remaining levels.
Assuming topic hierarchy is mandatory for all messaging.
Assuming topic hierarchy is mandatory for all messaging. Topic hierarchy is a helpful convention but not always required; simple flat topics can also be used.
Summary
Topics are named labels that organize messages by subject for sending and receiving.
Topic hierarchy uses slashes to create levels, grouping related topics like folders.
Wildcards '+' and '#' let subscribers listen to multiple topics flexibly within the hierarchy.