mqtt协议

mqtt协议中一些名词解释:

保留消息Retained Messages:

publish消息的时候设置的参数、当客户端或者服务器publish一条消息的时候将消息Retain标志设置为1,则服务器端会保存当前topic下的最后一条消息,当有新的客户端订阅这个topic时候,服务器会马上将此topic下的保留消息下发给它。

A retained message is a normal MQTT message with the retained flag set to true. The broker will store the last retained message and the corresponding QoS for that topic Each client that subscribes to a topic pattern, which matches the topic of the retained message, will receive the message immediately after subscribing. For each topic only one retained message will be stored by the broker.

清除会话Clean Session

清除会话标志是在客户端连接服务器的时候需要设置的参数、当客户端设置清除会话标志为0,则服务器端会存储客户端的连接信息和订阅主题信息,当客户端断开重连接时服务器能保证将客户端离线是错过的消息补发给它。需要注意的是当客户端设置清除会话标志为0时必要需要指定clientId,否则连接服务器出错。

MQTT clean session.  True = this session is to be treated as clean.  Previous server state is cleared and no stated is retained from this connection

遗言机制Last Will & Testament:

客户端连接服务器时需要设置的参数、客户端连接到服务器时指定遗言主题,并且指定遗言消息参数,当客户端断开连接时服务器会往当前主题下发送指定的遗言消息,内部实现是当客户端未及时发送心跳包则服务器断定客户端断开连接。

mqtt连接流程和消息质量

他只是向前航行,脚下是沉静碧蓝的大海,而头顶是金色的太阳。
原文地址:https://www.cnblogs.com/bliss-/p/12508774.html