当前位置:网站首页>学习太极创客 — MQTT 第二章(六)MQTT 遗嘱
学习太极创客 — MQTT 第二章(六)MQTT 遗嘱
2022-06-28 04:24:00 【xuechanba】
资料链接:http://www.taichi-maker.com/homepage/esp8266-nodemcu-iot/iot-tuttorial/mqtt-tutorial/mqtt-last-will/


当客户端正常断开连接时,会向服务端发送DISCONNECT报文,服务端接收到该报文后,就知道,客户端是正常断开连接,而并非意外断开连接。

然而,当服务端在没有收到 DISCONNECT 报文的情况下,发现客户端“心跳”停止了,这时服务端就知道客户端是意外断线了。
通过客户端软件再来举例:
正常连接时,

当点击 Disconnect 后,这是软件(客户端)就会向 MQTT 服务器发送一个 DISCONNECT 数据包,在此情况下,服务端就知道客户端是正常断开连接的。然而,如果我直接关闭软件或者电脑意外关机,此时,软件(客户端)就不会向 MQTT 服务器发送 DISCONNECT 数据包,也就是说只要客户端不向 MQTT 服务器发送 DISCONNECT 数据包,那么此时就是意外断开连接。

(只有订阅了遗嘱的客户端才能在发布的客户端意外断开连接时接收到遗嘱信息。)
1、客户端如何将遗嘱消息发送给服务端


下面通过 MQTT.fx 这个软件来操作下如何使用 MQTT 遗嘱,
首先,点击齿轮



设置好后,点击 OK ,就设置好了。
下面,我们再打开一个 MQTT.fx 软件,当作客户端来订阅上述客户端发布的主题,但是这里有一个很重要的步骤,那就是
1、将之前设置的遗嘱内容给删除掉,因为这里是作为客户端来订阅的,所以不需要这些内容。

2、点击重新生成 Client ID,这非常重要。

之后,点击 OK,就设置好了。

现在,我们将发布遗嘱的客户端意外断开(直接关闭软件),看看会有什么现象。

如果把遗嘱保留信息给勾选上 ,又会发生什么样的结果呢?
先打开一个软件并进行设置,

再打开一个软件(与上面说的再打开一个软件的设置一样)
之后,我们将发布遗嘱的客户端意外断开(直接关闭软件),看看会有什么现象。
同样的也会接收到遗嘱信息。
现在,再打开一个软件(设置也一样,主要是重新生成 ClientID),然后再点击订阅该遗嘱主题。
会发现立刻就收到了遗嘱信息。

而如果之前是正常断开连接的呢?
正常断开连接时并不会发送,当有其他客户端又订阅了该遗嘱信息时,还是会立刻就收到保留的遗嘱信息的,而不是等到意外断开时才收到。
最后,再来说一说 MQTT 遗嘱操作建议

(具体如何演示,在后面会介绍)
边栏推荐
- The SQL of filincdc always reports this error when there are multiple tables. How can I solve it
- Audio and video technology development weekly
- Source code of live video system, countdown display, countdown of commodity spike
- [csp-j2020] excellent splitting
- 大促场景下,如何做好网关高可用防护
- Games104 operation 2-colorgrading
- Project practice! Teach you JMeter performance test hand in hand
- How to clean the nozzle of Epson l3153 printer
- Why are cloud vendors targeting this KPI?
- 互联网的发展促进了无界零售、数字零售、即时零售等一系列新模式的出现
猜你喜欢

2022-06-27:给出一个长度为n的01串,现在请你找到两个区间, 使得这两个区间中,1的个数相等,0的个数也相等, 这两个区间可以相交,但是不可以完全重叠,即两个区间的左右端点不可以完全一样。

玩转双指针

mysql导入文本文件时的pager

Necessary skills for test and development: actual combat of security test vulnerability shooting range

100+数据科学面试问题和答案总结 - 机器学习和深度学习

Mask's miserable and inspirational childhood, who is introverted by campus violence

On the necessity of building a video surveillance convergence platform and its scenario application

Matlab exercises -- basic data processing

Performance optimization and implementation of video codec

Analysis of distributed transaction solution Seata golang
随机推荐
How to traverse collections Ordereddict, taking it and forgetting items
Meta universe standard forum established
Has anyone ever used CDC to synchronize to MySQL with a deadlock?
Flexible IP network test tool -- x-launch
UI自动化测试框架搭建 —— 编写一个APP自动化
inherit
几百行代码实现一个脚本解释器
Database garbled
Analyse complète annuelle du marché chinois de l'audio en 2022
判断对象中是否存在某一个属性
Project practice! Teach you JMeter performance test hand in hand
Difference between curdate() and now()
快速下载JDK,除了官方Oracle下载,还有国内可以有最新版本的下载地址吗
知识点滴 - 关于汉语学习的网络资源
With favorable policies, more than 20 provinces and cities have launched the yuanuniverse development plan
有人用cdc同步到mysql发生过死锁吗?
The growth summer challenge is coming | learn and create two major tracks, and start the tutor registration!
Detailed reading of the thesis: implementing volume models for handowriting text recognition
One article explains in detail | those things about growth
Matlab exercises -- exercises related to symbolic operation