MQTT protocol adopts an asynchronous communication paradigm based on publication and subscription (publish/subscribe).
When A node communicates with B node, it’s not synchronous as a phone call (i.e. immediate exchanges)
On the contrary, in MQTT protocol a message is published by A node (publish) and is received – even after some time – by B node that has subscribed reception (subscribe).
By using MQTT protocol, message production and receipt are uncoupled, even from a temporal point of view.
It is therefore a very different operating mode from other protocols, such as HTTP protocol – used by the web – which is request-response type.
MQTT protocol message exchange is managed by a broker, a server that receives messages from publishers and delivers them to subscribers. The broker only delivers messages that refer to the selected topics.
Topics are categories in which messages are logically grouped into. A topic could group all climatic data of an established environment or operating parameters of a given plant.
A temperature sensor can be considered as a publisher: it provides the broker with data, only the one relating to a requested topic
The subscriber, e.g. a data collector, connects to the broker and filters topics of interest, including the temperature probe readings.
Once the broker receives a publication on a topic, it will send the relating message to all subscribers. In this case, the broker will send only data received from the temperature sensor.
Data are sent from publisher in the message body (payload) by using a format formerly established between publisher and subscriber, which usually depends on application type.
It is often used a JSON structure as in the following example: