In this article, we are explaining all the terms related to the MQTT Protocol with the definitions and specified use cases. We have discussed ‘What is MQTT?’ An Introduction
in an earlier post so learn more about MQTT Protocol.
MQTT Broker is a server that receives all messages from the MQTT clients and then routes the messages to the appropriate destination MQTT clients. It’s clearly different from HTTP protocol which works on request-response protocol for client-server models. There are many public MQTT Brokers available in the market.
Like Mosquitto MQTT Broker is the best MQTT Broker for use in MQTT applications.
MQTT Client can be a small constrained device or full-fledged server which runs on MQTT Library and connects to the MQTT Broker over a network to Publish-Subscribe the topics. for ex.- ESP8266 works as an MQTT Client connected with different sensors publishing the value of the sensor to MQTT Broker and any other MQTT Client like MqttDesk Desktop Client subscribe to those values and visualize the real-time visualizations. There are no direct connections between publishers & subscribers.
The topic is a UTF-8 string that MQTT Broker uses to filter the messages from MQTT Clients. Each topic level is separated by forwarding slash, Topics are case-sensitive in MQTT Protocol like MqttDesk/MQTTClient/home/room1/led & MQTTDESK/MQTTCLIENT/HOME/ROOM1/LED both are different topics.
Payload is the data sent over the Network, each payload includes both header information, the actual data, and the Will message being sent. The header identifies the source and destination of the packet, while the actual data is referred to as the payload. Max. MQTT payload restriction is 256 MB but it depends on the MQTT Broker.
MQTT v5.0 & MQTT v3.0 are the main versions running on most of the MQTT Client & MQTT Brokers whereas MQTT v5.0 is the updated & advanced version with many good features.
Publish a topic is like when a client publishes to a topic it updates the data of that topic on MQTT Broker. Then MQTT Broker publishes the new messages to the Topic’s subscriber.
Subscribing a topic is like when a client subscribes to the topic from MQTT Broker. Multiple nos. of MQTT Client can subscribe to the same topic.
The topic filter is used by the MQTT lient to define its subscription to a topic. A subscription’s topic filter can contain wild cards to subscribe to multiple topics.
Single-level wildcards IN MQTT are used to match one topic level of hierarchy. This single-level (+) wildcard can be used more than once in the topic filter and in conjunction with the multi-level wildcard.
for example – If the client subscribes to ‘MqttDesk/home/+/led’, then the client will receive the messages published to both ‘MqttDesk/home/room/led’ and ‘MqttDesk/home/kitchen/led’.
Multilevel wildcards in MQTT are used to specify all remaining levels of hierarchies and it has to be the last character in the topic subscription.
for example – If the client subscribes to ‘MqttDesk/home/#’, then the client will receive the messages published to ‘MqttDesk/home/room’ , ‘MqttDesk/home/kitchen’ and ‘MqttDesk/home/Livingroom’
To be continued……