MQTT
MQTT is a lightweight publish/subscribe messaging protocol in which IoT devices exchange messages by topic through a central broker.
Stands for: Message Queuing Telemetry Transport (historical name)
MQTT was created in 1999 by Andy Stanford-Clark (IBM) and Arlen Nipper for satellite-linked pipeline telemetry. It is now an OASIS standard: v3.1.1 (2014, also ISO/IEC 20922) and v5.0 (2019). It runs over TCP (port 1883, or 8883 with TLS), and browsers can connect over WebSocket. Its fixed header starts at just 2 bytes, which suits low-bandwidth, unreliable links.
In the publish/subscribe model, clients do not know about each other. A publisher sends a message to a topic (e.g. factory/line1/temperature) and the broker delivers it to every client subscribed to that topic. In subscriptions, + is a single-level and # a multi-level wildcard. Retained messages give new subscribers a topic's last value immediately. Last Will and Testament is a predefined message the broker publishes on behalf of a client that disconnects unexpectedly, and it is the standard way to detect devices going offline.
There are three quality-of-service levels: QoS 0 at most once (no acknowledgement), QoS 1 at least once (duplicates possible) and QoS 2 exactly once (a four-step handshake, the most expensive). Persistent sessions let the broker queue QoS 1 and 2 messages while a client is offline. MQTT 5 added detailed reason codes, user properties, shared subscriptions for load balancing and message expiry, among other features. Popular brokers include Eclipse Mosquitto, EMQX and HiveMQ.
TLS, per-client authentication (username/password or client certificates) and topic-level access control lists (ACLs) are essential. Brokers left open to anonymous access are a common security hole. The topic hierarchy should be designed consistently from the start (e.g. customer/site/device/metric). In IoT systems, data polled from Modbus devices by gateways and sensor data from LoRaWAN network servers is most often delivered to the platform via MQTT. The MQTT-SN variant exists for highly constrained sensor networks.
Have a project in mind?
Tell us briefly what you want to set up, or give us a call. We'll pass it to the right team.