MQTT Protocol Reference
Reference 为 MQTT 3.1.1/5.0 pub/sub 协议为 IoT: topics, QoS, retain, 和最后将.
Pub/Sub Model
MQTT uses a publish/subscribe model where clients publish to topics and subscribe to receive messages. Topics use slash-separated hierarchical names with wildcards (+ for single level, # for multi-level). The broker filters and routes messages to subscribers. This decouples publishers from subscribers, enabling many-to-many communication. The protocol is lightweight, with a minimal 2-byte fixed header.
- topics
- Hierarchical names
- wildcards
- + single, # multi
- broker
- Message router
sensor/temp/room1 sensor/+/room1 decouples pub/sub QoS and Features
MQTT defines three QoS levels: 0 (at most once, fire and forget), 1 (at least once, acknowledged), 2 (exactly once, four-way handshake). Retained messages store the last message per topic for new subscribers. Last Will and Testament publishes a message if a client disconnects unexpectedly. MQTT 5.0 adds reason codes, shared subscriptions, topic aliases, and user properties. Keepalive detects stale connections.
- QoS 0
- At most once
- QoS 1
- At least once
- retain
- Store last message
no ack PUBACK new subs receive it