MQTT Essential 细节笔记总结(深入理解MQTT细节)

栏目: 后端 · 发布时间: 5年前

如何发现存在的Topic

The subscriber does not know which topics are available. We have seen many deployments where far more than 100.000+ topics are used in the system and sending these topic lists to subscribers would be overkill. The protocol itself does not define such a topic discovery. We have seen these two popular solutions in deployments:

* Subscribe to a custom $SYS topic which contains all available topics for the client (e.g. $SYS/{client_id}/topics). You can learn about hooking in custom $SYS topics

Debug调试的时候的信息的含义

“received PUBLISH (d0, q0, r0, m0, ‘get/123’, … (70 bytes))”

the fields have the following meaning:

d0 => duplicate flag: false

q0 => QoS: 0

r0 => retained: false

m0 => messageID: 0

想要收到有订阅者带走了消息?

MQTT本身无法做到,可以从业务层次实现,比如往另一个Topic里面推送数据

MQTT is a data agnostic protocol that can transfer any kind of information. For that sound files like in your case need to be first converted in byte array before the publish. The subscriber (receiver) needs than to convert back the received byte array.

retain消息不会影响当前已经连接的客户端

也就是只有新连接的客户端才会收到 retain 消息,已经连接的不会收到

One retained message for a specific topic (The last message published on the topic, regardless of the payload) can be stored by the broker so that any new subscribers on that specific topic will be able to get that message. This does not in any way influence the message flow of currently connected subscribers.

如何识别Payload里面的消息类型呢?是否有HTTP那样的Content-Type标志位?

没有任何标志位,可以通过Topic本身的分类来设置不同的消息类型,MQTT是消息无关的协议,不关心自己Payload里面的数据内容

cleanSesson标志位的作用

如果cleanSession=false 那么一旦客户端断开,则对应的Topic

QoS服务降级

只会降级不会升级,也就是会用最低服务质量(发布者发布的消息QoS和订阅者的QoS要求会使用最低质量服务)

如何保证订阅者可以收到所有的消息,即使离线?

All messages will be sent to client B automatically after the reconnect if all of the following conditions are met:

– Client B has been connected before with the clean session flag is false and has subscribe to the topic, where the messages arrive

– All messages were sent with quality of service greater than 0

You can read more on how the queuing works here:  http://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages

When looking at retained messages only the last message will be persisted on the topic. It will be delivered to a newly subscribing client, right after subscribing.

如何删除Retain消息?

发送一个含有retain标志位但是payload为空的数据

A zero byte payload message will not be forwarded to subscribers. It’s sole purpose is to clear a retained message on a topic.

如何再次收到retain消息?

断开重连或者取消订阅后重新订阅

The only way to “update” the retained message for a client is to re-subscribe to the topic.

LWT(Last Will Testament) 遗嘱消息什么时候删除?

当客户端Graceful disconnect的时候,它的遗嘱消息就会删除

LWT最佳实践

配合Retain消息使用,比如Retain设置设备在线,这样所有的订阅者都能查询设备状态,但是在LWT中则定义离线,一旦设备离线则broker则会发送离线消息

如果客户端的ID相同(client_id)会怎么样?

client_id用于识别会话,如果相同,这个问题很严重,会导致mqtt认为同一个客户端尝试重新连接,于是会关闭之前的连接然后再新建连接,对于死循环的客户端来说会导致服务器和客户端之间不断的断开和连接,非常消耗资源的死循环流程,因此没有特殊情况,可以不指定clientid,因为大部分库都能够良好的生成随机ID。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

大象无形:虚幻引擎程序设计浅析

大象无形:虚幻引擎程序设计浅析

罗丁力、张三 / 电子工业出版社 / 2017-4 / 65

《大象无形:虚幻引擎程序设计浅析》以两位作者本人在使用虚幻引擎过程中的实际经历为参考,包括三大部分:使用C++语言进行游戏性编程、了解虚幻引擎本身底层结构与渲染结构、编写插件扩展虚幻引擎。提供了不同于官方文档内容的虚幻引擎相关细节和有效实践。有助于读者一窥虚幻引擎本身设计的精妙之处,并能学习到定制虚幻引擎所需的基础知识,实现对其的按需定制。 《大象无形:虚幻引擎程序设计浅析》适合初步了解虚幻......一起来看看 《大象无形:虚幻引擎程序设计浅析》 这本书的介绍吧!

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具