Mqtt

What Is MQTT?

MQTT (Message Queuing Telemetry Transport) is a lightweight publish-subscribe messaging protocol designed for constrained devices and unreliable networks, standardized by OASIS as an international standard. Andy Stanford-Clark of IBM and Arlen Nipper developed the protocol in 1999 for monitoring oil pipelines via satellite link, where bandwidth was scarce and connection reliability could not be assumed. IBM submitted the protocol to OASIS for standardization in 2013, and MQTT version 3.1.1 was ratified as an international standard in November 2014. Version 5.0 followed in 2019, adding features for improved error handling, session expiry, and message property extensions.

The protocol's architecture centers on a message broker, which sits between devices sending data (publishers) and devices or services receiving it (subscribers). This decoupling allows publishers and subscribers to operate independently of each other's availability, with the broker buffering messages and delivering them according to configured quality-of-service (QoS) levels. The design trades the sophistication of protocols like HTTP for minimal overhead: a fixed header of as few as two bytes makes MQTT practical on microcontrollers with kilobytes of RAM.

Publish-Subscribe Model and Topics

MQTT organizes message routing around topic strings, which are hierarchical UTF-8 path identifiers such as sensors/building1/floor3/temperature. A publisher sends a message with a specific topic, and the broker delivers it to all clients that have subscribed to that topic or a matching wildcard pattern. Single-level wildcards (+) match one segment of the hierarchy, and multi-level wildcards (#) match all remaining segments, giving subscribers fine-grained control over which message streams they receive. The OASIS MQTT 5.0 specification defines the full topic filter syntax, packet structure, and protocol state machine.

Quality of Service and Session Persistence

MQTT defines three quality-of-service levels. QoS 0 delivers a message at most once with no acknowledgment, suitable for frequently sampled sensor readings where an occasional missed value is acceptable. QoS 1 guarantees at-least-once delivery using acknowledgment packets, which may result in duplicate messages. QoS 2 uses a four-part handshake to ensure exactly-once delivery, appropriate for commands or transactions where duplicates would cause errors. Clients can request a persistent session when connecting; the broker then stores subscriptions and any undelivered QoS 1 or QoS 2 messages, delivering them when the client reconnects. The Last Will and Testament (LWT) feature allows a client to pre-register a message that the broker will publish automatically if the client disconnects unexpectedly, supporting failure detection in distributed deployments.

Security and Protocol Versions

MQTT runs over TCP/IP and can be secured with TLS, which encrypts the connection and authenticates the broker to the client. Client authentication uses username-password credentials in the protocol itself, or client certificates at the TLS layer. MQTT 5.0 introduced enhanced authentication flows supporting challenge-response mechanisms beyond simple password exchange. The protocol also runs over WebSockets (often called MQTT over WS), enabling browser-based clients to connect to brokers through standard HTTPS ports. The mqtt.org resource page maintains the list of conformant brokers, client libraries, and tools across dozens of programming environments.

Applications

MQTT has been adopted across a range of fields, including:

Loading…