清泛IT社区App Inventor 2 中文社区

搜索

扫码访问移动社区 移动社区,您的掌上技术专家

关注我,精彩不错过! 关注我,精彩不错过!

扫码安装最新版AI伴侣 最新版AI伴侣v2.72

Aia Store .aia 源码一站式解决方案 发布日志AI2连接测试ai2Starter模拟器

开通会员送SVIPApp Inventor 2 拓展有奖征文 VIP会员享专有教程,免费赠送基础版*技术支持服务! AI2入门必读中文文档中文教程IoT专题

查看: 634|回复: 0
打印 上一主题 下一主题

[经验分享] MQTT 之保留消息(Retained Messages)

  • TA的每日心情
    开心
    3 小时前
  • 签到天数: 208 天

    [LV.7]常住居民III

    446

    主题

    738

    帖子

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    18007

    AI2中文网VIP弹球达人接水果达人撸猫达人

    跳转到指定楼层
    楼主
    发表于 2024-07-15 15:22:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    保留消息定义

      如果PUBLISH消息的RETAIN标记位被设置为1,则称该消息为“保留消息”;

    Broker对保留消息的处理

      Broker会存储每个Topic的最后一条保留消息及其Qos,当订阅该Topic的客户端上线后,Broker需要将该消息投递给它。

    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.
    保留消息作用

      可以让新订阅的客户端得到发布方的最新的状态值,而不必要等待发送。

    A retained message makes sense, when newly connected subscribers should receive messages immediately and shouldn’t have to wait until a publishing client sends the next message. This is extremely helpful when for status updates of components or devices on individual topics. For example the status of device1 is on the topic myhome/devices/device1/status, a new subscriber to the topic will get the status (online/offline) of the device immediately after subscribing when retained messages are used. The same is true for clients, which send data in intervals, temperature, GPS coordinates and other data. Without retained messages new subscribers are kept in the dark between publish intervals. So using retained messages helps to provide the last good value to a connecting client immediately.
    保留消息的删除
    • 方式1:发送空消息体的保留消息;
    • 方式2:发送最新的保留消息覆盖之前的(推荐);

    参考:https://blog.csdn.net/renanrenan/article/details/83380800

    App Inventor 2 中文网 - MIT同步更新的中文本土化平台!v2.72 支持Android 14 更新日志
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    © 2024 tsingfun.com, Inc.  沪ICP备2020034476号-1  沪公网安备31011702000040号

    GMT+8, 2024-09-08 08:52 , Processed in 0.017335 second(s), 32 queries .