MQTT

MQTT is a lightweight, publish–subscribe, machine-to-machine network protocol for message queueing/message queuing services.

Uses your system voice; voice and rate in settings.

Snapshot

≈ 4 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

MQTT is a lightweight, publish–subscribe, machine-to-machine network protocol for message queueing/message queuing services. It is designed for connections with remote locations that have devices with resource constraints or limited network bandwidth, such as in the Internet of things (IoT).

It must run over a transport protocol that provides ordered, lossless, bi-directional connections—typically, TCP/IP. It is an open OASIS standard and an ISO recommendation (ISO/IEC 20922).

Overview

The MQTT protocol defines two types of network entities: a message broker and a number of clients. An MQTT broker is a server that receives messages from publishing clients and then routes the messages to the appropriate destination clients.

An MQTT client is any device (from a microcontroller up to a full-fledged server) that runs an MQTT library and connects to an MQTT broker over a network. Information is organized in a hierarchy of topics. When a publisher has a new item of data to distribute, it sends a control message with the data to the connected broker.

The broker then distributes the information to any clients that have subscribed to that topic. The publisher does not need to have any data on the number or locations of subscribers; and subscribers, in turn, do not have to be configured with any data about the publishers.

If a broker receives a message on a topic for which there are no current subscribers, the broker discards the message unless the publisher of the message designated the message as a retained message. A retained message is a normal MQTT message with the retained flag set to true.

The broker stores the last retained message and the corresponding quality of service (QoS) for the selected topic. Each client that subscribes to a topic pattern that matches the topic of the retained message receives the retained message immediately after they subscribe. The broker stores only one retained message per topic.

This allows new subscribers to a topic to receive the most current value rather than waiting for the next update from a publisher. When a publishing client first connects to the broker, it can set up a default message to be sent to subscribers if the broker detects that the publishing client has unexpectedly disconnected from the broker.

Clients only interact with a broker, but a system may contain several broker servers that exchange data based on their current subscribers' topics. A minimal MQTT control message can be as little as two bytes of data. A control message can carry nearly 256 megabytes of data if needed.

There are 14 defined message types used to connect and disconnect a client from a broker, to publish data, to acknowledge receipt of data, and to supervise the connection between client and server. MQTT relies on the TCP protocol for data transmission. A variant, MQTT-SN, is used over other transports such as UDP or Bluetooth.

MQTT sends connection credentials in plain text format and does not include any measures for security or authentication. This can be provided by using TLS to encrypt and protect the transferred information against interception, modification or forgery. The default unencrypted MQTT port is 1883.

The encrypted port is 8883.

Security

MQTT protocol version 3.1.1 requires the server (broker) to use a timeout that is one-and-a-half times the keepalive value specified by the client. This (and similar keepalive functionalities in other protocols such as HTTP) enables a slow DoS attack published in 20201 called SlowITe, in which the attacker tries to open and maintain as many connections as possible, depriving legitimate users of their connections.

New variations of the attack and new detection/mitigation methods are topics of current research.

Clustering

The MQTT specification defines communication between a client and a single broker and does not specify communication between brokers. Deployments that need more capacity or availability than a single broker provides rely on implementation-specific mechanisms.

The two common approaches are bridging, in which one broker connects to another broker as a client and forwards messages for selected topics, and clustering, in which a group of broker nodes shares subscription and session state and appears to clients as a single logical broker. Eclipse Mosquitto implements bridging through broker configuration.

Clustered brokers such as EMQX and HiveMQ run as multi-node systems whose nodes share client sessions, topic subscriptions, and routing information. A 2020 study that compared distributed deployments of three MQTT brokers on an edge-gateway cluster found substantial differences between implementations in throughput, latency, and message loss during node failure.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1378586122 under CC BY-SA 4.0; modifications have been made.

References

  1. ↩Wikipedia “MQTT” revision 1378586122 · retrieved 2026-10-20 publication date (×1) · confidence 0.95 revision URL