MQTT(7)
π MQTT(7) β like, the conventions & miscellaneous page, bestie
okay so first things first, this whole page lives under the MQTT manual section (section 7, the "conventions and miscellaneous" girlies), and it's brought to you by the Mosquitto Project. yes we're doing the manual page thing. stay with me, it's gonna slay.
β¨ NAME β¨
mqtt β MQ Telemetry Transport. that's the whole name, that's the vibe. π¦
β¨ SYNOPSIS β¨
MQTT
literally just MQTT. no flags, no args, no drama. iconic behavior honestly. π
β¨ DESCRIPTION β¨
so MQTT is a lightweight publish/subscribe messaging protocol β lowkey the blueprint. it's genuinely useful for low power sensors, but no cap it works for so many scenarios, it's not just a sensor thing.
this manual walks you through some of the features of MQTT version 3.1.1/3.1, so you (the end user) can get the absolute most out of the protocol. π«Ά for the full, complete, all-the-tea info on MQTT, go look at https://mqtt.org/ β that's where the rest lives.
πΈ PUBLISH/SUBSCRIBE πΈ
the MQTT protocol is built on one principle and it's very main character: you publish messages and you subscribe to topics. aka "pub/sub". π¬
here's the whole situation:
- multiple clients connect to a broker and subscribe to topics they're interested in
- clients also connect to that broker and publish messages to topics
- many clients can subscribe to the same topics and do whatever they want with the info β their choice, their era
the broker and MQTT act as a simple, common interface for everything to connect to. which means: if you've got clients that dump subscribed messages into a database, to Twitter, or even just a plain text file β then adding new sensors or other data input to that database, Twitter, whatever, becomes genuinely so simple. it's giving plug and play. β¨
π TOPICS/SUBSCRIPTIONS π
messages in MQTT get published on topics. and here's the cute part: there is no need to configure a topic β just publishing on it is enough. no setup arc, no registration form, we simply go. π
topics are treated as a hierarchy, using a slash (/) as a separator. same energy as a filesystem, which means you can arrange common themes sensibly. for example, multiple computers can all publish their hard drive temperature info on this topic, with their own computer name and hard drive name swapped in as appropriate:
sensors/COMPUTER_NAME/temperature/HARDDRIVE_NAME
clients receive messages by creating subscriptions. a subscription can be to an explicit topic (in which case only messages to that exact topic get received), or it can include wildcards. there are exactly two, and they are + and #.
π« the + wildcard
+ can be used as a wildcard for a single level of hierarchy. so you could take the topic above and get info on all computers and hard drives like this:
sensors/+/temperature/+
another example β for a topic of "a/b/c/d", these example subscriptions will match:
a/b/c/d+/b/c/da/+/c/da/+/+/d+/+/+/+
and these subscriptions will not match (sorry bestie):
a/b/cb/+/c/d+/+/+
π₯ the # wildcard
# can be used as a wildcard for all remaining levels of hierarchy. and because of that, it must be the final character in a subscription. rules are rules. π
with a topic of "a/b/c/d", these example subscriptions will match:
a/b/c/d#a/#a/b/#a/b/c/#+/b/c/#
π the zero-length level lore
zero length topic levels are valid, which leads to some slightly non-obvious behaviour. hear me out:
- a topic of
"a//topic"would correctly match against a subscription of"a/+/topic" - zero length topic levels can exist at both the beginning and the end of a topic string
- so
"/a/topic"would match against a subscription of"+/a/topic","#"or"/#" - and a topic
"a/topic/"would match against a subscription of"a/topic/+"or"a/topic/#"
like yes it's a little unhinged but it's also correct. iykyk. π
π QUALITY OF SERVICE π
MQTT defines three levels of Quality of Service (QoS). the QoS defines how hard the broker/client will try to make sure a message is actually received. π
the rules:
- messages may be sent at any QoS level
- clients may attempt to subscribe to topics at any QoS level
- this means the client chooses the maximum QoS it will receive
examples, because examples ate:
- if a message is published at QoS 2 and a client is subscribed with QoS 0 β the message is delivered to that client with QoS 0
- if a second client is also subscribed to the same topic but with QoS 2 β it receives the same message, but with QoS 2
- if a client is subscribed with QoS 2 and a message is published on QoS 0 β the client receives it on QoS 0
higher levels of QoS are more reliable, but they come with higher latency and higher bandwidth requirements. tradeoffs, always tradeoffs. π
- 0 β the broker/client will deliver the message once, with no confirmation
- 1 β the broker/client will deliver the message at least once, with confirmation required
- 2 β the broker/client will deliver the message exactly once by using a four step handshake
β RETAINED MESSAGES β
all messages may be set to be retained. what that means: the broker keeps the message even after it's been sent to all current subscribers. π«Ά
then, if a new subscription is made that matches the topic of the retained message, that message gets sent to the client. it's basically a "last known good" mechanism, and it's lowkey genius.
why you care: if a topic is only updated infrequently, then without a retained message a newly subscribed client may have to wait a long time to get an update. with a retained message, the client gets an instant update. instant. periodt. π₯
π§ CLEAN SESSION / DURABLE CONNECTIONS π§
on connection, a client sets the "clean session" flag β sometimes also known as the "clean start" flag. two names, same flag, we love a versatile icon.
- if clean session is set to false, the connection is treated as durable. this means when the client disconnects, any subscriptions it has will remain, and any subsequent QoS 1 or 2 messages will be stored until it connects again in the future. it waits for you. π₯Ή
- if clean session is true, then all subscriptions will be removed for the client when it disconnects. clean slate, no baggage.
π WILLS π
when a client connects to a broker, it may inform the broker that it has a will. this is a message the client wishes the broker to send when the client disconnects unexpectedly. πβ¨
the will message has a topic, a QoS and a retain status, just the same as any other message. no special treatment, it's just built different by being ominous.
π SEE ALSO π
mosquitto(7), mosquitto(8), mosquitto_pub(1), mosquitto_sub(1)
π AUTHOR π
Roger Light <roger@atchoo.org> β the legend themselves π«Ά
and that's the page bestie!! π
this gorgeous little artifact comes to you courtesy of the Mosquitto Project, dated 02/09/2026, living as always in the MQTT(7) section. now go publish something iconic. π¦ππΈ
π¦ where this page comes from
- alpine 3.24: mosquitto-doc 2.1.2-r1 Β· EPL-1.0 OR EPL-2.0
- fedora 44: mosquitto 2.1.2-1.fc44 Β· EPL-2.0
- fedora 44: mosquitto 2.1.2-1.fc44 Β· EPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms