MQTT — Message Queuing Telemetry Transport protocol was founded by Andy Stanford-Clark (IBM) and Arlen Nipper in 1999. It’s a publish/subscribe messaging protocol used in IoT for interconnecting devices in a secure way with light bandwidth and high latency. This protocol is designed in such a way that it consumes very little battery power. So, it is mainly used in IoT devices since it has minimal battery capacity.
The MQTT protocol has two core parts: a Client and a Broker. The Broker is a server and all other clients are connected. If clients want to send a message to a server or broker is called Publish and if the client receives the messages on subscribed topic from Broker is called Subscribe. Multiple clients are connected to the brokers and subscribed to the interesting topic and clients publish the message to the Broker.
The MQTT topics are a form of addresses used to send and receive the message. There is no required configuration on the topic just send a message over the topic. The slash ‘/’ symbol represents the hierarchy of the sub-topic. For example, home automation topics could be
The subscriber can subscribe to an Absolute topic or can use a wildcard. The operator + and # are used in wildcards. The wildcards are used only in Subscribe not publish
+ — Single level wildcard can apply anywhere in the topic
It represents the doorstate on Alex’s house in A block. If we would like to subscribe all doorstate in all blocks in apartment ABC.
# — Represents all remaining levels of hierarchy. The following topic subscribes all sensor state in apartment ABC
The Brokers acts as a server and it is responsible for receiving all messages and sending messages to the subscribed clients. The benefits of Broker
- Eliminate insecure connections
- Easily Scalable
- Manage Client Connection State
- Reduce Network Load
The Broker can handle thousands of concurrency connections depending upon implementation. The broker is also responsible for authentication and authorization of client connections.
MQTT is most used in IoT applications to capture real-time analytics and monitoring environments such as smart home, healthcare, automobile, industrial maintenance, etc.