MQTT Topic Namespace: Best Practices & Step by Step Guide

Content

A clearly structured MQTT topic namespace is crucial for efficient communication within an Industrial Unified Namespace (UNS). The combination of hierarchical organization and precise definition of topics creates the basis for a flexible, scalable and user-friendly architecture. This article describes proven best practices and provides a step-by-step guide to developing an effective MQTT topic namespace.

 

What is an MQTT Topic?

MQTT topics serve as communication channels in the MQTT protocol, under which MQTT clients can publish and subscribe to defined messages. A topic is a UTF-8 character string that acts as a unique identifier. MQTT topics consist of one or more levels, which are separated by a slash (/) (topic level). This structure enables a hierarchical organization of information and provides a filter mechanism for messages. Example: A temperature sensor could use the following MQTT topic to publish the process temperature of a specific work cell:

This structure increases the flexibility and precision of data exchange, as clients can only subscribe to and receive the relevant information within the specified topic hierarchy.

 

How are MQTT topics defined?

In MQTT, topics are defined by a connected system when a message is published. The client creates a topic string under which the message is published. The process in detail:

  1. Publisher: A system that wants to send data via MQTT defines the topic string and publishes the message under this name in the broker.
  2. Broker: The MQTT broker receives the message and distributes it to all subscribers.
  3. Subscriber: Clients receive this message if they have subscribed to the topic.

 

 

Best Practices

The following best practices support the creation of a clearly structured MQTT topic hierarchy, which is the basis of a scalable Industrial Unified Namespace (UNS) architecture.

 

1. Ensure clarity

Unambiguous topics are essential to ensure smooth data transmission between MQTT clients and brokers. Clear and unambiguous topic naming prevents conflicts and enables smooth interoperability within the industrial ecosystem. Note: MQTT topics are case-sensitive. This means that x/y and X/y are treated as two different topics.

 

2. Standardization across factories

It is crucial to develop a consistent topic structure for the entire company. This structure should be applicable in all facilities, production lines and machines. At the same time, individual requirements at different organizational levels can be taken into account by introducing separate topics for special use cases, e.g. .enterprise/site/area/workCell/individual

 

3. Granularity vs. Modularity

A good balance between granularity and modularity is crucial. The decision for granularity or modularity should be based on the requirements of your use cases.

  • Granularity enables the detailed mapping of individual data points, such as a temperature value in a specific topic .../temperature. This makes it easier to subscribe to specific events and data in a targeted manner.
  • Modularity combines several data points in a common topic, which supports the clarity and scalability of the MQTT namespace. For example, all sensor data, such as temperature, pressure and humidity, can be published together in a topic such as .../sensor.

 

4. Hierarchical organization

The topic structure should reflect a clearly defined hierarchy that reflects the physical and logical structure of your industrial ecosystem. A tree-like organization of topics makes it possible to place broader categories at higher levels (e.g. “factory” or “production line”) and more specific topics (e.g. “orders” or “sensor data”) below. This offers several advantages:

  • Clarity: A well-structured hierarchy makes it easier to understand and navigate within the MQTT namespace.
  • Flexibility: New topics can be easily integrated into the existing structure without jeopardizing consistency.
  • Efficiency: Clients can subscribe to a broad data overview or very specific information in the underlying topics at a higher level.

 

5. Context-related naming

Use clearly and meaningfully named topics that clearly convey context and purpose. Well thought-out, contextual naming makes it easier for users to understand the content and function of each topic and reduces potential misunderstandings. This increases user-friendliness and improves clarity within the MQTT namespace. Example: Instead of .../data, use .../machine1/status for more precise information. This gives a clear indication of the content without requiring additional documentation.

 

6. Integrate versioning

As the MQTT namespace evolves over time, it is advisable to integrate versioning into the MQTT topic hierarchy. This makes it easier to manage changes and ensures backward compatibility. Versioning allows new structures to be introduced without affecting existing systems. An example of the integration of versioning v1/.../areaID/lineID/cellID or mySpec/v1/.../areaID/lineID/cellID .

 

7. Additional recommendations

  • Avoid making topic names unnecessarily long to increase readability.
  • Do not use MQTT-specific characters such as #, +, / and $, as they have special functions in the MQTT protocol.
  • Spaces should be avoided as they can lead to confusion or cause problems in some systems.
  • Only use ASCII characters and no non-printable characters.

 

 

Step-by-Step guide to developing an MQTT topic namespace

With a clear understanding of best practices, an effective MQTT topic hierarchy can be developed step by step. A pilot use case provides a good basis for gradually expanding the structure.

 

Step 1: Define pilot use case

Identify all relevant IT and OT systems that are to communicate via MQTT as part of the pilot use case. This ensures that the MQTT topic structure meets the specific requirements and provides you with practical guidance for the next steps.

 

Step 2: Define hierarchy levels

Create a multi-level hierarchical structure that maps the different components of your industrial ecosystem. These levels could include factories, production lines and machines. Such an approach provides a clear and well-organized framework, often based on the ISA95 standard.

ISA 95 based MQTT Topic Namespace

What is ISA95?
ISA95 is an internationally recognized standard that defines models and terminologies for the integration of OT and IT systems in manufacturing. This standard helps to structure the hierarchy of topics in an MQTT-based Unified Namespace (UNS) and ensures that information is logically organized and easily accessible.

 

Step 3: Identify subtopics

Determine the relevant data categories that need to be exchanged between the systems in the pilot use case. These data categories can be raw data, control commands, production orders or KPIs. Every company has different data categories at the various hierarchy levels, which are either shared company-wide or exclusive and individual for a specific level.

ISA 95 based MQTT Topic Namespace

 

Step 4: Consider metadata

Metadata provides additional context to the data that you distribute via MQTT (e.g. device identifiers, manufacturer information or units of measurement). They can either be integrated directly into the message payload, the topic string or in separate topics.

 

Step 5: Validation and testing

Before implementation in the production environment, you should validate and test your MQTT topic hierarchy, ideally in a controlled test environment. This allows potential problems to be identified and rectified at an early stage.

 

Step 6: Iterative refinement

The MQTT topic hierarchy must adapt to changing requirements and progress in your Unified Namespace (UNS). Implement a continuous improvement process that takes into account regular feedback from users. Ensure that maintainability is guaranteed by incorporating versioning into your topic hierarchy (see above).

 

Step 7: Regular cleanup

Perform a regular cleanup of the MQTT topic namespace to remove obsolete elements such as inactive topics or disconnected systems.

 

Conclusion

A well thought-out MQTT topic namespace is an essential building block for efficient communication and data organization within an Industrial Unified Namespace (UNS). The combination of best practices such as uniqueness, hierarchical organization and contextuality enables a scalable, flexible and user-friendly architecture. Thanks to an iterative approach, regular testing and continuous improvements, the topic hierarchy remains adaptable and future-proof.

About i-flow: i-flow is an industrial software company based in southern Germany. We offer manufacturers the world’s most intuitive software to connect factories at scale. Over 400 million data operations daily in production-critical environments not only demonstrate the scalability of the software, but also the deep trust our customers place in i-flow. Our success is based on close collaboration with customers and partners worldwide, including renowned Fortune 500 companies and industry leaders like Bosch.

Try it out now - free trial version

Experience the unlimited possibilities that i-flow offers by taking a test for yourself. Test now for 30 days free of charge on your systems.

Your question has not been answered? Contact us.

Your Contact:

Marieke Severiens (i-flow GmbH)
content@i-flow.io