MQTT is a lightweight message transport protocol developed in 1999. Since this protocol is very lightweight and bandwidth-efficient, it is best suitable for IoT applications with different wireless sensor network communications that are involved.
It follows the PubSub model which is a publisher-subscriber model that is entirely different from the HTTP protocol’s Request/Response model. One of the key features of MQTT is that it is an asynchronous protocol. The client need not be connected with the broker for the operation.
Client: A device that publishes messages on a particular topic (publisher) or receives messages by subscribing to a particular topic (subscriber). They are connected to a central server where they maintain persistent connectivity or transiently.
Broker: The server which receives forwarding the messages sent by the publishers to all the subscribers and maintains a connection with clients.
Topic: A namespace/string for identifying messages to the broker/client. It is an endpoint used to address different data received by the broker and requested by subscribers.
Publish: Action of sending/dispatching the data to the broker
Subscribe: Client action indicating the interest in receiving a topic updates
Pub/Sub model
In the PubSub model, the clients don’t connect directly, instead, they are connected through a broker. The communication between publisher and subscribers are not directly either and the broker acts as a communication link between clients. Clients send messages by specifying a topic. Subscriber clients subscribe to interesting topics and messages from that topic are sent by the broker once they receive them. This model ensures that both subscriber and clients need not be connected all the time and directly each other, which enhances the security of each client.