当前位置:网站首页>学习太极创客 — 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 遗嘱操作建议

(具体如何演示,在后面会介绍)
边栏推荐
- Has any boss ever seen repeated binlog messages when MySQL CDC uses datastream
- Ppt production tips
- 华为9年经验的软件测试总监工作感悟—写给还在迷茫的朋友
- Matlab exercises -- basic data processing
- Are test / development programmers really young? The world is fair. We all speak by strength
- Where does the storm go? Whose pot is the weather forecast wrong?
- Function and working principle of controller
- Moonbeam integrates coin98, giving users more choices on the multi chain road
- Array method
- 多线程实现 重写run(),怎么注入使用mapper文件操作数据库
猜你喜欢

Multithreading and high concurrency IV: varhandle, strong weak virtual reference and ThreadLocal

Idle interrupt cannot be cleared
![[applet] solution document using font awesome Font Icon (picture and text)](/img/1b/d1b738e6e35e59cc4a417df4ea0e8d.png)
[applet] solution document using font awesome Font Icon (picture and text)

Why is the frame rate calculated by opencv wrong?

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

Audio and video technology development weekly

Analyse complète annuelle du marché chinois de l'audio en 2022

Taco: a data enhancement technique for character recognition

一文详解|增长那些事儿

Sword finger offer 53 - I. find the number I in the sorted array (improved bisection)
随机推荐
June 27, 2022: give a 01 string with a length of N. now please find two intervals so that the number of 1 and the number of 0 in the two intervals are equal. The two intervals can intersect, but not c
[CSP-J2020] 优秀的拆分
If mysqlcdc sets multiple parallelism, will the incremental data repeat?
Role of native keyword
A bit of knowledge - online resources on Chinese Learning
Array method
互联网的发展促进了无界零售、数字零售、即时零售等一系列新模式的出现
Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e
【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】
[NOIP2002 普及组] 过河卒
Principle and implementation of SSD for target detection
Mise en place d'un cadre d'essai d'automatisation de l'interface utilisateur - - rédaction d'une application d'automatisation
inherit
Annual comprehensive analysis of China's audio market in 2022
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
Google Earth Engine(GEE)——全球洪水数据库 v1 (2000-2018年)
Is it true that qiniu business school gives away securities accounts? Is it safe to open an account
2022年G3锅炉水处理复训题库模拟考试平台操作
测试开发必备技能:安全测试漏洞靶场实战
Principle of event delegation