On this page
MQTT
The most concise pub/sub protocol designed for low-bandwidth, high-latency, and unreliable IoT networks—QoS 0/1/2 provide three levels of delivery guarantees, retained messages enable state synchronization, and will messages handle offline notifications. MQTT 5.0 adds enterprise features such as session expiry and shared subscriptions.
Overview
MQTT (Message Queuing Telemetry Transport, 1999/2013) is the most concise pub/sub messaging protocol, specifically designed for low-bandwidth, high-latency, and unreliable IoT networks. Publishers do not connect directly to subscribers—all messages pass through a broker (Mosquitto/EMQX), and topics support wildcard filtering. QoS 0/1/2 provide three levels of delivery guarantees, while retained messages and will messages enable state synchronization and offline notifications. MQTT 5.0 (2019) adds enterprise features such as session expiry and shared subscriptions.
Model
MQTT is a minimalist pub/sub protocol designed for low-bandwidth, high-latency, and unreliable networks (IoT, M2M). All messages pass through a central broker (Mosquitto, EMQX):
QoS
MQTT CONNECT/CONNACK
CONNECT:
protocol_name: "MQTT" (v3.1.1) or "MQIsdp" (v3.1)
protocol_level: 4 (v3.1.1) or 5 (v5.0)
flags: clean_session, will_flag, will_qos, will_retain, password_flag, username_flag
keep_alive: seconds (publisher must send PINGREQ within keep_alive seconds)
client_id: unique ID (or empty → broker assigns, v5.0 only)
[will_topic, will_message] ← if will_flag=1
[username, password]
CONNACK:
session_present: 0 (new session), 1 (existing session resumed)
return_code: 0=success, 1-5=failure reason
Will Message
Declared when the client connects: "If I disconnect unexpectedly, the broker sends this message": CONNECT will_topic + will_message + will_retain. If the client disconnects abnormally (TCP close or keepalive timeout) → the broker publishes the will message.
MQTT 5.0 Improvements
- Session expiry: How long the session is retained after disconnection (QoS 1/2 messages in the queue continue)
- Message expiry: TTL for a single message
- Shared subscriptions: Load balancing among multiple subscribers (round-robin)
- Reason codes: All ACK messages include specific reasons
- Topic aliases: 1/2-byte aliases replace full topic names → saves bandwidth
References
- broker: Eclipse Mosquitto (C), EMQX (Erlang), VerneMQ
- tools:
mosquitto_pub -h broker -t topic -m "hello", MQTT Explorer
Keywords: MQTT, pub/sub, QoS, retained, will, Mosquitto, IoT, topic filter