MQTT QoS duplicate message idempotent processing - PLC Playground troubleshooting guide

MQTT Counter Increments Twice? QoS Does Not Define Your Business Transaction

Message delivery guarantees do not automatically make an application action unique. If production totals increment twice after reconnect, inspect duplicate handling and event identity before lowering the MQTT quality-of-service level.

Original event-processing example; MQTT delivery and business processing are separate contracts.

What is happening?

MQTT QoS describes protocol delivery behavior between participating endpoints. QoS 1 permits redelivery, and application retries or republishing can create additional logical duplicates. A consumer needs a defined event-processing contract.

Check these five things

  1. Identify the configured QoS at each relevant connection.

  2. Capture event identities and payloads around reconnect.

  3. Separate transport redelivery from a new publication.

  4. Implement reviewed duplicate detection where required.

  5. Test consumer restart and persistence of deduplication state.

Worked example

A teaching publisher sends event 812 for one completed part. The consumer records it, then sees the same logical event again after recovery. Incrementing blindly counts two parts; accepting the identity once preserves one business event even if delivery repeats.

Quick diagnostic reference

Layer Question
Transport Was a packet redelivered?
Publisher Was the event republished?
Consumer Was identity already accepted?

The mistake to avoid

Assuming QoS 2 eliminates every end-to-end duplication ignores application behavior outside one protocol exchange. Define the complete producer-to-storage transaction.

How to verify the fix

Replay known events through disconnects and restarts. Verify exactly the intended logical count, while keeping evidence of rejected duplicates and incomplete transactions.

Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.

Technical reference

HiveMQ: MQTT Essentials. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.

Continue troubleshooting

Previous Post