MQTT - Getting Started Continued

1. The message model:

 MQTT is a broker-based publish/subscribe messaging protocol. Provides one-to-many message distribution to decouple applications. A publisher can correspond to multiple subscribers. When the publisher changes, he can notify all the subscribers of the message one by one. This mode provides greater network scalability and a more dynamic network topology. 

2. Message quality

  MQTT provides three qualities of service:   1) At most once, packet loss may occur. Used in situations where real-time requirements are not high. This level can be used in scenarios such as environmental sensor data, where it doesn't matter if one read is lost because the next one will be generated soon. 

  2) At least once, the packet is guaranteed to reach the destination, but there may be heavy packets.

  3) Exactly once, to ensure that the package will reach the destination, and there will be no heavy package phenomenon. This level can be used in scenarios such as billing systems where lost or duplicated messages may result in incorrect charges being generated.

3. Theme name

  The topic name (Topic name) is used to identify the channel through which the information of the published message. Subscribers use it to ensure that the information of interest has been received. It is a layered structure with a slash "/" as a delimiter. There are two wildcards that can be used when publishing and subscribing to a topic: "#" and "+". The former can be wildcarded with a multi-layer structure, while the latter can only be wildcarded with a one-layer structure. For example a topic: "a/b/c", then "a/+/c" and "a/#" can be equal to it. Publishing does not support fuzzy matching and must be a definite topic.

4. Survivors

  When a client disconnects, it expects the client to send the message it specifies. This message has the same structure as a normal message. By setting this bit and filling in the content related to the information.

6. Message Type

name value Flow direction describe
Reserved 0 prohibit Reserve
Connect 1 client to server Client to server connection request
ConnACK 2 server to client The server's response to the connection request
Publish 3 Both directions are allowed Publish message (QoS0)
puback 4 Both directions are allowed Response to QoS1 publish message
pubRec 5 Both directions are allowed Received release message (QoS2 guaranteed transmission first step)
pubRel 6 Both directions are allowed Release the publish message (QoS2 guaranteed transmission second step)
pubComp 7 Both directions are allowed Finish publishing the message (the third step of QoS2 guaranteed transmission)
subscribe 8 client to server Client Subscription Request
subBack 9 server to client Confirmation of subscription request
unsubscribe 10 client to server Client unsubscribe request
unsubBack 11 server to client Unsubscribe request confirmation
pingReq 12 client to server Ping (heartbeat) request (keep connection)
pingResp 13 server to client Ping (heartbeat) response
disconnect 14 client to server Client disconnects
reserved 15 prohibit Reserve

To develop an MQTT library, you need to provide the following commands:

Connect : The command to be used when a TCP/IP socket is connected between the server and the client.

publish : It is sent by the client to the server, telling the server the topic it is interested in. Each publishMessage will be associated with a Topic name.

pubRec: is the response to the publish command, but uses a level 2 QoS protocol. It is the second message of the level 2 QoS protocol

pubRel: is the third message of the level 2 QoS protocol

publComp: is the fourth message of the level 2 QoS protocol

subscribe: Allows a client to register the Topic names it is interested in, and messages published to these Topics will be sent by the server to the client in the form of a publish Message.

unsubscribe: From the client to the server, unsubscribe a Topic.

Ping: There is a "are you alive" message sent by the client to the server.

disconnect: disconnect this TCP/IP protocol

3. MQTT server and client

https://github.com/mqtt/mqtt.github.io/wiki/servers

https://github.com/mqtt/mqtt.github.io/wiki/libraries

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324951551&siteId=291194637