PUBLISH SUBSCRIBE MODEL
In this model, the device wanting to send a message connects to the broker. Once the connection is established then it publishes the message. Every message has defined Topics associated with them.
In the figure, we have the humidity sensor publishing the humidity percentage on the topic “Humidity”. This data is picked up by the MQTT broker and stored under the topic “Humidity” along with additional parameters like from which sensor was it received and at what time was it received.
All the messages on a given Topic are queued in a First In First Out (FIFO) sequence by the MQTT broker. The data collected is stored in a database. In this case, the humidity percentages which are received from the Humidity Sensor device get stored in a message queue. Especially in the case of IoT devices, the frequency of the data sent would be a lot more when the tracking and position data is being sent.
The broker then checks which devices are subscribed to the topic of Humidity. These messages queued up are then sent by the broker to all the devices that are subscribed to the Humidity topic. In this case, the humidity controller and the temperature controller both receive the humidity data since they are both subscribed to the topic of humidity. As temperature increases the relative humidity increases hence these two controllers need to work in tandem to ensure optimum humidity control.