A brief introduction to MQTT

mqtt (message queuing telemetry transport) is a "lightweight" communication protocol based on publish/subscribe mode, which is built on TCP/IP protocol. For example, if you send an email to a friend, you can do something else after sending it, and the recipient doesn't have to respond immediately. You can check the email at your own time. It is a typical asynchronous publish/subscribe scenario. Another typical synchronous request/answer scenario can be compared with the scene of answering the phone.

The design of MQTT follows the following principles:

In order to meet different scenarios, MQTT supports three different levels of Quality of Service (QoS) to provide message reliability for different scenarios:

MQTT has 14 different message types:

The communication between client and server is required to realize MQTT protocol. In the communication process, there are three identities in MQTT protocol: publisher (publisher). Among them, the publisher and subscriber of the message are both clients, the message agent is a server, and the publisher of the message can be a subscriber at the same time.

messages transmitted by mqtt are divided into two parts: Topic and payload.

MQTT will build the underlying network transmission: it will establish the connection between the client and the server, and provide an orderly, lossless, two-way transmission based on byte stream between them.

when application data is sent through MQTT network, MQTT will associate the related quality of service (QoS) with Topic name.

an application or device using MQTT protocol, which always establishes a network connection to the server. The client can be:

MQTT server called "message Broker", which can be an application or a device. It is located between the message publisher and the subscriber, and it can:

Subscription contains Topic Filter and maximum quality of service (QoS). Subscriptions are associated with a Session. A session can contain multiple subscriptions. Each subscription in each session has a different topic filter.

after each client establishes a connection with the server, it is a session, and there is state interaction between the client and the server. A session exists between one network, or it may span multiple consecutive network connections between a client and a server.

connect to the label of an application message, which matches the subscription of the server. The server sends a message to each client that subscribes to the matching label.

a wildcard filter for topic names, which is used in subscription expressions to indicate multiple topics that the subscription matches.

what the message subscriber specifically receives.

some methods (also called actions) are defined in the mqtt protocol to represent the operations performed on certain resources. This resource can represent pre-existing data or dynamically generated data, depending on the implementation of the server. Generally speaking, resources refer to files or outputs on the server. The main methods are: