跳到主要内容
uencoder

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
sensor/temp/room1
wildcards
+ single, # multi
sensor/+/room1
broker
Message router
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
no ack
QoS 1
At least once
PUBACK
retain
Store last message
new subs receive it

相关工具

参考链接