MQTT messages are sent to Topics which provide context and other information about the message. Topics are hierarchical paths that allow Subscribers to use wildcards to select multiple Topics. Therefore, Topics are most useful when they follow a predictable pattern. This clause defines the Topic conventions for use with the MQTT mapping. All Publishers shall be able to support these conventions.

A Topic has the following general pattern:

<Prefix>/<Encoding>/<MqttMessageType>/<PublisherId>/[<WriterGroup>/<DataSetWriter>]

Where Topic levels are:

  • <Prefix> is a system defined prefix that provides a scope for the PublisherIds;The default value is ‘opcua’.
  • <Encoding> specifies the encoding of messages sent to the Topic (‘json’, ‘uadp’, etc);
  • <MqttMessageType> specifies the content of the messages published to the Topic as defined in 7.3.5.7.2;
  • <PublisherId> uniquely identifies a Publisher within the scope of the prefix;
  • <WriterGroup> is the name of a WriterGroup within the Publisher;
  • <DataSetWriter> is the name of a DataSetWriter within the WriterGroup;

The <Prefix> should be one Topic level, however, system designers may break <Prefix> into multiple Topic levels. Note that using multiple Topic levels prevents Subscribers from automatically discovering Publishers in the system unless they are preconfigured with the <Prefix> used for the system.

The possible values for the <Encoding> are ‘json’ or ‘uadp’ based on the message mappings defined in 7.2.3 and 7.2.4.6.9.

When Publishers are configured to publish to an MQTT Broker they shall have PublisherId assigned that can be used as Topic level.

The Topic levels that appear after the <PublisherId> depend on the <MqttMessageType>.

When these Topic conventions are used the wildcards in Table 177 may be used:

Table 177 – Examples of MQTT Wildcards

Wildcard

Notes

opcua/json/status/#

Subscribes to the status of all Publishers in the “opcua” scope.

This allows the Subscriber to detect when Publishers come online or disappear.

opcua/json/metadata/#

Subscribes to the metadata of all Publishers in the “opcua” scope.

This allows the Subscriber to detect changes to metadata.

opcua/json/data/device-one/#

Subscribes to all data produced by Publisher “device-one” in the “opcua” scope.

opcua/json/data/+/+/diagnostic

Subscribes to all Publishers that offer a “diagnostic” writer.

The MQTT Topic syntax places restrictions on what characters may be used in a Topic level. Specifically, Topic levels are any UTF8 string that:

  • Does not start with a $
  • Does not include /, + or #
  • Does not include non-printable characters or whitespace other than the space character (U+0020).