Explainer
Why one OPC UA PubSub MQTT connection can serve two topics
Short answer
Yes: two PubSubConnection entries in the .NET Standard stack open independent MQTT connections to one broker, and one connection with multiple WriterGroups already serves several topics. QueueName and MetaDataQueueName decide the topic. The stack supports UDP UADP, MQTT UADP and MQTT JSON, so Kafka or Redis Streams need a bridge, not a new broker address.

On this page
- What the stack opens for two PubSubConnection entries
- Where the topic comes from: QueueName and MetaDataQueueName
- A separate topic does not need a separate connection
- Worked example: one connection carrying two DataSets
- The transport profiles this stack supports
- Kafka or Redis Streams: a bridge, not a broker address
- The decision, case by case
- Questions asked
Yes — in the .NET Standard stack every PubSubConnection entry opens its own independent MQTT connection, so two entries pointed at the same broker run as two separate sessions on it. A separate topic is not a reason to add a second entry: one connection with multiple WriterGroups already carries several topics over a single session, and the topic itself is decided by QueueName and MetaDataQueueName, not by the connection count. On the transport side this stack supports exactly three PubSub profiles — UDP UADP, MQTT UADP and MQTT JSON — which is why Kafka or Redis Streams need a bridge rather than a new broker address. The sections below show where topics come from, when a second connection earns its place, and what each choice costs.
What the stack opens for two PubSubConnection entries #
Two PubSubConnection entries that both target mqtt://broker.example.com operate as independent MQTT connections to that broker. Sharing the broker address does not merge them into one session, and the reverse holds too: two configuration entries do not prove that two sessions exist, because each entry has to complete its own TCP or TLS handshake, its own broker authentication and its own subscriptions before any data flows.
Independence also stops at the connection level. Two sessions on one broker still share that broker's capacity, its availability and every switch between the PC and the broker, so a second entry buys transport isolation, not a second broker.
Confirm both sessions on the broker side: most brokers expose a connected-client view where each MQTT session appears with its client identifier, and two healthy entries produce two rows there. If starting the second entry drops the first, compare the client identifiers the two connections actually present before touching the topics. And because each entry resolves the broker address on its own, a hostname that only some hosts on the network can resolve leaves one session offline while the other connects — the case described in whether a local MQTT broker needs a static IP address.
No package version is pinned to any of this behavior here; record the stack build you actually run before chasing an implementation-specific fault.
Where the topic comes from: QueueName and MetaDataQueueName #
In this MQTT transport the topic is a configuration match, not a discovered address. QueueName is the topic on which the transport publishes or consumes DataSet messages, and MetaDataQueueName does the same job for the metadata that describes a DataSet; the OPC UA Part 14 MQTT topic clause (7.3.4.7) defines these conventions, and the stack applies them in its transport layer.
Two consequences follow. First, publisher and subscriber must spell the same QueueName identically — separators and case included — or you get a session that connects cleanly and decodes nothing. Second, metadata is consumed on its own topic, so a subscriber can receive data bytes and still show no values when the metadata topic never matched or was never authorized.
An example split, with the topic strings as example values: PubSubConnection1 publishes on sensor/temperature and PubSubConnection2 on sensor/humidity, both to mqtt://broker.example.com. Each DataSetWriter carries its own QueueName, and the stack's example publisher configuration method, CreatePublisherConfiguration_MqttJson, shows how connection, WriterGroup and DataSetWriter relate in one configuration tree.
A separate topic does not need a separate connection #
The question behind the two entries is usually "one topic, one connection?". The answer is no: a single PubSubConnection can hold multiple WriterGroups, and each WriterGroup can carry its own DataSets, so several topics ride one MQTT session. The connection count follows from transport needs, not from the number of topics.
| Design | Choose it when | What it costs |
|---|---|---|
| One PubSubConnection, multiple WriterGroups | Topics share a broker, a listener and a lifecycle | One session, one authentication, one reconnect path |
| Two PubSubConnection entries, one broker | The paths must open, close or fail independently, or terminate at different listeners | Two sessions, two authentications, two client identities |
| Two entries as a throughput fix | Never on its own | Both sessions still share the broker, so no bandwidth is added |
Two entries give connection-level separation only: an application shutdown stops both, and a broker outage interrupts both. Splitting connections does not preserve data emitted while a session is down either — that needs store-and-forward at the application, the problem covered in buffering MQTT messages while the broker connection is down.
Worked example: one connection carrying two DataSets #
Worked example with illustrative values. An edge publisher runs one PubSubConnection to the plant broker: WriterGroup A emits a temperature DataSet every 1,000 ms, WriterGroup B emits a humidity DataSet every 5,000 ms. The shared session carries the sum:
- 1,000 ms ÷ 1,000 ms = 1.0 temperature messages per second
- 1,000 ms ÷ 5,000 ms = 0.2 humidity messages per second
- total 1.2 messages per second on one MQTT session
Split the same two writers across two PubSubConnection entries and the broker still receives 1.2 messages per second, because both sessions share the broker and the network path — splitting adds no throughput. What changes is the failure shape: a broken session now interrupts one topic stream instead of both, and the broker sees two client identities instead of one. That is the whole benefit, and it is a real one when the streams have different owners or different tolerances for downtime.
The transport profiles this stack supports #
The PubSub specification defines five transport profiles, and this implementation supports the first three:
| Transport profile | Mapping and medium | In this stack |
|---|---|---|
| PubSub UDP UADP | UADP binary over multicast UDP | Supported; no broker involved |
| PubSub MQTT UADP | UADP binary over MQTT | Supported |
| PubSub MQTT JSON | JSON over MQTT | Supported |
| PubSub AMQP UADP | UADP over AMQP | Not supported |
| PubSub AMQP JSON | JSON over AMQP | Not supported |
The two MQTT profiles are what a broker-based deployment uses: UADP is the compact binary framing that needs the matching decoder at every receiver, JSON is readable text that gateways and scripting tools parse directly. The UADP mapping carries framing parameters of its own, and one documented failure mode is a writer whose key-frame setting is silently ignored — the case analyzed in why KeyFrameCount is ignored on UADP messages.
One caution belongs here: the JSON mapping adds no protection of its own, because the specification states that JSON encoded message bodies depend on the security mechanisms of MQTT and the broker — so a JSON stream leaving the trusted network relies entirely on the broker listener's TLS, its authentication and its topic authorization.
Kafka or Redis Streams: a bridge, not a broker address #
Kafka, ZeroMQ and Redis Streams are not PubSub transports, and no value typed into the connection address turns the MQTT transport into a Kafka producer. The table above is the whole menu for this stack; AMQP exists as a defined profile pair the stack does not implement, and nothing at all exists for the streaming systems.
Translation belongs in a bridge: a separate process that consumes the MQTT topic with one of the supported profiles and republishes into the target system. The bridge owns payload conversion, topic-to-destination mapping, metadata handling, delivery behavior and reconnection, none of which the PubSub writer will do for it. Writing a native custom transport is a software project against the stack's transport abstractions, not a configuration change, and the two carry very different maintenance commitments.
One adjacent trap: a broker that accepts MQTT is not thereby a Sparkplug system. PubSub MQTT JSON and Sparkplug are different topic and payload conventions riding the same protocol, so a Sparkplug host will not read PubSub topics — the distinction is laid out in why MQTT broker support is not Sparkplug support.
The decision, case by case #
- Two topics, one broker, one owner, one lifecycle: one PubSubConnection with a WriterGroup per topic. The streams share the session's bandwidth and one reconnect path.
- Topics that must fail or be maintained independently, or that terminate at different listeners: two PubSubConnection entries. Verify two rows on the broker's connected-client list after start-up.
- Data that must land in Kafka, ZeroMQ or Redis Streams: keep the MQTT JSON profile and put a bridge beside the broker; editing the connection address changes nothing.
- A subscriber connects but shows no values: compare the QueueName strings on both sides and check the metadata topic before touching the WriterGroups.
Questions asked
If one of the two sessions drops the other, what is wrong?
Almost always a shared MQTT client identifier. The broker tells sessions apart by the identifier each client presents, and a new connect with an identifier already in use is treated as a replacement, so the broker disconnects the older session. Read the identifier each PubSub connection actually sends, visible on the broker's connected-client list, rather than assuming the PubSub connection name becomes the MQTT identity.
Should I choose the MQTT UADP or the MQTT JSON transport profile?
Both ride the same broker; the difference is the payload. UADP is compact binary framing that every receiver must decode with the matching OPC UA encoder settings, and it keeps messages small at high rates. JSON is readable text that gateways and scripting tools parse without a binary decoder, at the cost of larger messages. Choose the profile every receiver in the path can decode; a mixed fleet forces the lowest common decoder.
What does the metadata topic carry?
MetaDataQueueName selects a second topic that describes the DataSet rather than carrying its values: the field structure a subscriber needs to decode the data topic correctly. Because the two ride different topics, a subscriber can receive bytes on the data topic and still show nothing when the metadata topic was never matched or never authorized. Verify both topics on the broker, not just the data one.
Who buffers data while the Kafka side of a bridge is down?
The bridge, by explicit design. The PubSub writer keeps publishing to the MQTT broker and has no knowledge of the bridge's target, so nothing buffers on the publisher side unless you add it. Give the bridge a store-and-forward queue sized for the longest expected target outage at your message rate, and decide the drop policy, oldest first or newest first, before deployment rather than during the first outage.


