IMD SolutionComputing LibraryShop main store

How-to

Connecting MQTT Transmission to Azure Event Grid MQTT broker

Edge computing and IIoT Published 6 min read

Short answer

MQTT Transmission can now publish Sparkplug B through Azure Event Grid MQTT Broker because the broker supports retained messages and LWT. Match the Primary Host ID on both modules, set the MQTT Engine reorder timeout above your measured worst-case delivery displacement, and keep every message under the broker's 1 MB limit.

On this page
  1. What the Sparkplug path needs from the broker
  2. Connect both modules to the Event Grid namespace
  3. Match the Primary Host ID on both modules
  4. Set the MQTT Engine reorder timeout for out-of-order delivery
  5. Checking a 900 kB birth payload against the 1 MB ceiling
  6. Verify the commissioned path end to end
  7. Questions asked

Yes — MQTT Transmission can publish Sparkplug B through Azure Event Grid MQTT Broker on a compliant path. The broker supports the two MQTT features that Sparkplug host-state coordination needs, retained messages and the Last Will and Testament (LWT), and it accepts Sparkplug B traffic natively over TLS. Commissioning turns on three constraints: the Primary Host ID must match exactly on MQTT Transmission and MQTT Engine, MQTT Engine needs a reorder timeout sized for Event Grid's out-of-order delivery, and every published message must stay under the broker's 1 MB message-size limit. This article walks the broker connection, the host-state match, the timeout sizing, the size check and the end-to-end verification.

What the Sparkplug path needs from the broker #

Sparkplug B coordinates host state through two MQTT mechanisms. A retained message stores the last known value on a topic, so a module that connects later receives the current host STATE immediately instead of waiting for a fresh publication. The Last Will and Testament is the message a client registers when it connects, and the broker publishes it if that client disappears ungracefully, which is how an edge node's offline condition gets announced.

MQTT Transmission could not integrate with Event Grid until retained messages were supported, because the primary-host handshake had no stored state to land on. The broker now supports retained messages and LWT, stores the last known good value per topic, and accepts Sparkplug B messages natively over TLS, so the Transmission and Engine pair you would point at a conventional broker can point here, provided the three constraints above are handled.

Connect both modules to the Event Grid namespace #

Work the transport before Sparkplug semantics. Both modules connect to the same Event Grid namespace, each as an independent MQTT client, and if either connection will not hold, tracing an edge gateway MQTT connection failure to Azure Event Grid covers the endpoint, port and certificate checks before any Sparkplug setting matters.

  1. Create a distinct client identity and credentials for MQTT Transmission and a second, different identity for MQTT Engine. MQTT admits one session per client identity, so two connections presenting the same identity knock each other off the broker in a connect-and-disconnect loop.
  2. Enter the namespace endpoint and its configured listener port in MQTT Transmission, together with the certificate trust the TLS listener requires, and confirm the session holds without reconnect cycling.
  3. Repeat the endpoint and security configuration in MQTT Engine under its own client identity.
  4. Apply topic authorization so Transmission may publish its Sparkplug topics and Engine may subscribe to the same namespace. A connected status alone proves nothing about authorization; the check is a test publication that reaches the Engine subscription without an authorization error.

Match the Primary Host ID on both modules #

Run both modules with a Primary Host ID, the configuration this retained-message and LWT support exists to enable. MQTT Engine acts as the Sparkplug primary host and publishes its STATE; MQTT Transmission reads that retained state and publishes operational data only while it recognizes the host as online. The Primary Host ID string must be identical on both modules, including letter case: a spelling or case mismatch creates two different host identities even while both broker sessions look healthy, and Transmission withholds its data.

If Transmission still will not recognize the host after the strings match, work through the failure signature in why MQTT Transmission fails to validate the primary host online.

Two proofs close this stage: a newly connected subscriber receives the retained host state without a fresh publication, and dropping a client ungracefully produces its LWT-published offline status on the same topic.

Set the MQTT Engine reorder timeout for out-of-order delivery #

Traffic through Event Grid may arrive out of order, and Sparkplug consumers detect order through per-edge-node sequence numbers, so a later message arriving first reads as a gap. The reorder timeout in the MQTT Engine configuration exists for exactly this: Engine holds a suspect message briefly and restores sequence order instead of raising a sequence error on every burst.

Size it from measurement, not a guess. Capture arrival order for a day of representative traffic, including broker reconnect bursts, and take the worst displacement between the order the broker received messages and the order Engine saw them. Set the timeout to at least twice that worst measured displacement, then tighten it once the logs show a stable margin.

Two limits remain. A timeout reorders what arrives and cannot recover a message the broker never delivered, and any traffic published at QoS 0 has a separate loss window; that window is what covering the QoS 0 loss window in Sparkplug MQTT transmission addresses.

Checking a 900 kB birth payload against the 1 MB ceiling #

The inputs:

  • Maximum message size: 1 MB, the broker's documented limit on Event Grid. Read it as 1,000 kB, the smaller reading, so the margin never depends on which definition of MB applies.
  • Birth payload: 900 kB, an example measurement from a serialized edge-node birth on a comparable system — substitute the value you measure on yours. Birth messages carry every tag in the node, so the birth, not a steady-state data message, is the size test.

The rule: every message the broker evaluates must sit below the ceiling with headroom for the next commissioning change, because the birth aggregates all tags and grows whenever the tag set grows.

The arithmetic:

  • Headroom: 1,000 kB - 900 kB = 100 kB.
  • Share of the ceiling: 100 / 1,000 = 0.10, which is 10 percent.
  • Share of the birth itself: 100 / 900 = 0.11, about 11 percent.

Result: the birth passes today, at 90 percent of the conservative ceiling.

Decision: hold at least 20 percent headroom. At 10 percent, split the edge node or device into multiple nodes, move tags to other nodes, or enable payload compression before the next tag set is added — not after the first broker rejection of an oversized birth.

Verify the commissioned path end to end #

  1. Connect MQTT Engine to the namespace and confirm a stable authenticated session.
  2. Confirm Engine publishes its STATE and that a fresh subscriber retrieves the retained host state, with the Primary Host ID identical on both modules.
  3. Connect MQTT Transmission and confirm its session holds without reconnect cycling.
  4. Confirm the edge-node birth and any device births arrive and Engine populates the metrics in the intended namespace.
  5. Change one test tag and confirm the data message reaches Engine with the new value and a current timestamp, with no sequence alarm.
  6. Break Transmission's network path without a clean disconnect and confirm Engine receives the offline status published through the will; restore the link and confirm Transmission republishes its births and data resumes.
  7. After any tag-set change, re-measure the serialized birth and redo the headroom arithmetic against the ceiling.

The decision set in one place: declare the connection good when both sessions hold and the test publication reaches the Engine subscription; declare the host-state match proven when Transmission recognizes the Primary Host ID and a birth populates its metrics; call the reorder timeout correct when a day of representative traffic produces no sequence errors at the chosen window; and pass the size check only when the serialized birth sits at least 20 percent below the ceiling. A check that fails points back to its own section above, in the order given.

Questions asked

Why would MQTT Transmission not work against Event Grid before retained messages were supported?

A Sparkplug primary host announces itself with a retained STATE message, and a broker that cannot store retained messages has nothing to hand a late-joining client. Without that stored state, Transmission never sees the primary host as online and withholds operational data, so no compliant path exists. Retained-message and LWT support together completed both halves of the host-state mechanism.

What does a Primary Host ID mismatch look like when both clients show connected?

Both modules keep healthy broker sessions while Transmission treats the host identity it sees as a different, unknown host and withholds operational data; edge nodes can sit visible but idle, or stop updating while data messages never arrive. Match the Primary Host ID string exactly on both modules, including letter case, and the host is recognized on the next connection.

What happens if the MQTT Engine reorder timeout is shorter than the real delivery displacement?

Engine observes a sequence gap and logs a sequence error for that edge node; the late message can be dropped or applied against stale state until the next birth re-synchronizes the node, so values lag or jump. Set the timeout above the measured worst-case displacement. A longer window costs latency, not data.

How do you measure the serialized size of a birth payload before the broker rejects it?

Subscribe to the Sparkplug topics with a test client that saves every message, reconnect the edge node so it publishes a fresh birth, and read the byte size of the saved birth. Births carry every tag in the node, so they are the size test; data messages carry a handful of changed values and stay far smaller.

Keep reading

  • Explainer

    MQTT broker support is not Sparkplug support

    No. A compliant MQTT broker carries Sparkplug traffic without knowing it exists: to the broker the payload is opaque bytes, and the topic namespace, payload encoding and birth/death state conventions are implemented entirely by the publishing and subscribing clients. Verify Sparkplug support at both endpoints, never in the broker.

    Edge computing and IIoT

  • Troubleshooting

    Rebirth fails after switching Sparkplug MQTT brokers

    After a broker switch, Sparkplug telemetry arriving on the new connection proves only the inbound path. A rebirth request must leave through the client session that is actually connected on the enabled MQTT Server; when the module mishandles multiple server connections, the NCMD publish fails as client offline and no births return. Verify the replacement connection once, re-establish the birth baseline, and run a module build with the documented multi-server rebirth correction.

    Edge computing and IIoT

  • Troubleshooting

    Trace Ignition Edge MQTT values that only update on refresh

    Values that appear only after a refresh mean the Edge transmitter publishes nothing on its own: the forced republish masks a stalled change-driven path. Set a 10,000 ms scan rate with a 0.00000001 deadband and a moving signal publishes at the scan rate, then verify by counting 6 updates per minute with no refresh anywhere. Trace tag value and timestamp at each hop to find where it stops.

    Edge computing and IIoT