当前位置:网站首页>学习太极创客 — 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 遗嘱操作建议
(具体如何演示,在后面会介绍)
边栏推荐
- Ppt production tips
- Is it better for a novice to open a securities account? Is it safe to open a stock account
- One article explains in detail | those things about growth
- 2022-06-27:给出一个长度为n的01串,现在请你找到两个区间, 使得这两个区间中,1的个数相等,0的个数也相等, 这两个区间可以相交,但是不可以完全重叠,即两个区间的左右端点不可以完全一样。
- 2022年低压电工考题及答案
- How to traverse collections Ordereddict, taking it and forgetting items
- Analysis of distributed transaction solution Seata golang
- 【Matlab红绿灯识别】红绿灯识别【含GUI源码 1908期】
- Google Earth engine (GEE) - global flood database V1 (2000-2018)
- 判断对象中是否存在某一个属性
猜你喜欢
Ppt production tips
如何遍历collections.OrderedDict,服了又忘记items
[csp-j2020] excellent splitting
Sword finger offer 47 Maximum gift value (DP)
IP数据报的发送和转发过程
灵活的IP网络测试工具——— X-Launch
Why is the frame rate calculated by opencv wrong?
UI automation test framework construction - write an app automation
大促场景下,如何做好网关高可用防护
Why are cloud vendors targeting this KPI?
随机推荐
[proteus simulation] timer 1 external counting interrupt
Multithreading and high concurrency II: detailed introduction to volatile and CAS
The development of the Internet has promoted the emergence of a series of new models such as unbounded retail, digital retail and instant retail
UI自动化测试框架搭建 —— 编写一个APP自动化
控制器的功能和工作原理
Feign remote call fallback callback failed, no effect
filinCdc 的sql,多表的时候总报这个错,请问下该怎么解决呀
Why is the frame rate calculated by opencv wrong?
Is it better for a novice to open a securities account? Is it safe to open a stock account
mysql导入文本文件时的pager
2022年中国音频市场年度综合分析
Idle interrupt cannot be cleared
Analyse complète annuelle du marché chinois de l'audio en 2022
xml  File read / write
native关键字的作用
2022高处安装、维护、拆除考试题及答案
Flinkcdc collects Oracle, and the Oracle database is CDB's
MySQL gets the current date of the year
Resolve cross domain
27 years, Microsoft IE is over!