Skip to content

EMQX Will Message Not Published on Disconnect

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about EMQX Will Message Not Published on Disconnect. We cover key concepts, practical examples, and best practices.

The Problem

Will message (Last Will and Testament) does not publish when the client disconnects unexpectedly.

Quick Fix

Wrong

mqttx pub -t status -m 'online'  # No will message configured
When client disconnects, no "offline" notification sent.
# Set will message on connection
mqttx sub -t test -h broker -p 1883 \
  -u user -P pass \
  --will-topic 'client/status' \
  --will-message 'offline' \
  --will-qos 1 \
  --will-retain

# Publish online status
mqttx pub -t client/status -m 'online' -r

# Monitor will
mqttx sub -t client/status -v
"offline" appears on client/status topic after client disconnects unexpectedly.

Prevention

Will message is sent on: client disconnects without DISCONNECT packet, keep-alive timeout, or network failure. Configure wills at CONNECT time (cannot be changed after). Will QoS 1 or 2 ensures delivery. Retain flag allows clients to see last known status. Use TLS to prevent will spoofing.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What topics should I use for will messages?

Use a dedicated topic per client: clients/{clientid}/status. Include retain flag so subscribers get the last state.

Can I set will message after connecting?

No. The will is set during CONNECT and is immutable. Reconnect with a new CONNECT packet to change it.

Does will message work with MQTT 5.0?

Yes. MQTT 5.0 adds Will Delay Interval for delayed will publication.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro