MQTT (Message Queuing Telemetry Transport) is a client-server publish/subscribe messaging transport protocol that is lightweight, open, simple, simple in design, and easy to implement. Although HTTP is the epic standard for web pages, for large-scale communication between machines (Machine-to-Machine, M2M), the previous request/response (Request/Response) model is no longer suitable, and is replaced by publish/subscribe (Publish/ Subscribe) mode. Therefore, MQTT is already an indispensable standard protocol for the Internet of Things.
The characteristics of MQTT make it ideal for use in many situations, including constrained environments such as machine-to-machine (M2M) and Internet of Things (IoT) environments.
The protocol runs over TCP/IP or other network protocols that provide ordered, lossless, two-way connections. Its functions include:
– Use the publish/subscribe messaging model to provide one-to-many message distribution and application decoupling.
– Messaging transport independent of payload content.
– Three qualities of service for messaging:
- “At most once”, messages are delivered on a best-effort basis based on the operating environment. Message loss may occur. For example, this level could be used for environmental sensor data, where it does not matter whether an individual reading is lost because the next reading will be released soon.
- “At least once” ensures that the message arrives, but duplication may occur.
- “Exactly once” ensures that the message arrives exactly once. For example, in a billing system, where duplicate or missing messages may result in incorrect charges, this level may be used.
– Minimize transmission overhead and protocol switching, reducing network traffic.
– A mechanism to notify relevant parties when disconnection occurs abnormally.
client:
With a program or device using MQTT, the client always establishes a network connection to the server, which can
- Post application news that may be of interest to other customers.
- Subscribe to the requesting application messages it is interested in receiving.
- Unsubscribe to remove requests for application messages.
- Disconnect from the server.
server:
A program or device that acts as an intermediary between clients that publish application messages and clients that have subscribed, a server
- Accept network connections from clients.
- Accepts application messages published by the client.
- Handles subscription and unsubscribe requests from clients.
- Forward application messages that match the client’s subscription.
Application message:
The MQTT protocol enables applications to transfer data across networks. When MQTT transmits application messages, they have associated quality of service and topic names.
subscription:
Subscriptions include topic filters and maximum QoS. Subscriptions are associated with a single session. A session can contain multiple subscriptions. Each subscription in a session has a different topic filter.
Session:
Stateful interaction between client and server. Some sessions last only for the duration of a network connection, and some sessions can span multiple consecutive network connections between the client and server.
Topic name:
Label attached to application messages that match subscriptions known to the server. The server sends a copy of the application message to each client with a matching subscription.
Topic filtering:
An expression contained in a subscription that indicates interest in one or more topics. Topic filters can contain wildcard characters.
MQTT control package:
A packet of information sent over a network connection. The MQTT specification defines 14 different types of control packages, one of which (publish package) is used to deliver application messages.