Introduction
What can you tell about the monitored device and measured feature based on MQTT Topic?
MQTT Topics are highly flexible and do not force any structure. We should wisely use that compelling feature.
I saw companies struggling with MQTT because they lacked a standardized approach to the MQTT Topic definition. Every department/team used a different Topic structure leading to massive integration challenges. I created this guide to show how you can effectively organize the MQTT Topic structure following:
- Topic’s Purpose
- Business Entity
- Metadata
- Monitored Object
- Measured Feature
Topic Purpose
I propose to start with the purpose separation. We want to differentiate data (dt) topics from command (cmd) topics. That is a good security practice and simplifies access management. For example, most devices send data messages and should not be allowed to send commands.
Business Entity
The second level should be the business entity. That might be hard to grasp, but it actually makes sense. The business entity level helps to manage access permissions between departments and provides an extensible structure enabling future acquisitions.
Metadata
Then we define the metadata - data about data. We use topic levels to describe the characteristics of transferred information. This part is tricky because it is use-case specific and hard to standardize. It requires practice and experimentation to make it right, but the most important is understanding the intent.
Monitored Object
Identifying the monitored device/object/entity follows the metadata section. We want to embed that information into the MQTT Topic to make it actionable. For example, applications can filter incoming messages based on that value.
Measured Feature
Finally, we put the measured feature. This way, the temperature monitoring logic can easily extract only relevant measurements and process them accordingly. We should leverage this section to create restrictive access permissions. For example, the temperature monitoring logic should not have access to the device’s firmware version.
Summary
Please be aware that there is no one size fits all solution to this task. I used a tangible example to describe the objective of the thoughtful MQTT Topic structure definition. Adjust this approach to your needs, and you will avoid many issues when working with MQTT.
Let me know in case of any questions!