What is MQTT Protocol and its working?
Overview
MQTT (Message Queuing Telemetry Transport) is an open OASIS and ISO Standard (ISO/IEC 20922) lightweight publish/subscribe messaging protocol designed of M2M i.e. Machine to Machine telemetry in low bandwidth environments. The MQTT protocol runs over TCP/IP but any other network protocol which can provide lossless, bi-directional and ordered connections can support MQTT Protocol.
Andy Stanford-Clark (IBM) and Arlen Nipper in 1999, designed the MQTT protocol.
How Does MQTT Protocol Work? (Publish / Subscribe Model)
Consider the below figure depicting the architecture of the MQTT Publish / Subscribe Model
The MQTT Protocol defines three type of entities
- MQTT Broker
- Publisher
- Subscriber
The MQTT Broker is a server which receives any message that is published by a publisher and it routes that message to the subscriber subscribing for that topic.
Then comes the publisher. The publisher is a device which publishes a message with a specific topic.
Now the subscriber is a device which subscribes to a particular topic and receives the message intended for the topic subscribed.
Now coming to the working of MQTT protocol as explained below.
- A device connects to the MQTT Broker and subscribes to a topic in that broker. This connection can either be a plain TCP/IP Connection or it can be an encrypted TLS Connection.
- A device then publishes a message for a topic and sends that message along with the topic to the broker.
- The broker then sends the message published from the publisher to all the devices subscribing to that topic.
Here a device can be a publisher as well as a subscriber. Also a device can subscribe to multiple topics.
Advantages of MQTT Protocol
MQTT Protocol brings with itself many powerful advantages:
- Increase Scalability.
- Extremely Lightweight.
- Efficiently distributes information with reduced network bandwidth.
- Saves development time.
- The flexibility of this protocol makes it possible to support varied application scenarios for IOT devices and services.