MQTT QoS的用途/目的是什么? [英] What is the use/purpose of MQTT QoS?

查看:435
本文介绍了MQTT QoS的用途/目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究MQTT协议,看来规范的第一行存在矛盾:

I am studying the MQTT protocol and it seems that there is a contradiction in the very first lines of the specs:

协议通过TCP/IP或其他可运行的网络协议运行 提供有序的,无损的双向连接.它的特点 包括:

The protocol runs over TCP/IP, or over other network protocols that provide ordered, lossless, bi-directional connections. Its features include:

[...]

三种服务质量 邮件传递:

Three qualities of service for message delivery:

  • 最多一次",其中消息是 根据操作环境的最大努力交付. 可能会丢失消息.例如,此级别可用于 环境传感器数据是否独立读数无关紧要 已丢失,因为下一本将很快出版. ·
  • 在 至少一次",可以确保邮件到达,但重复的邮件可以 发生. ·
  • 恰好一次",确保消息到达 一次.例如,该级别可用于结算 邮件重复或丢失可能导致错误的系统 正在收取费用.
  • "At most once", where messages are delivered according to the best efforts of the operating environment. Message loss can occur. This level could be used, for example, with ambient sensor data where it does not matter if an individual reading is lost as the next one will be published soon after. ·
  • "At least once", where messages are assured to arrive but duplicates can occur. ·
  • "Exactly once", where message are assured to arrive exactly once. This level could be used, for example, with billing systems where duplicate or lost messages could lead to incorrect charges being applied.

如果MQTT只能在无损的网络协议上运行,那么提供有损QoS级别(0级)是什么意思?

If MQTT can only run over network protocols that are lossless, what is the meaning of providing a lossy level of QoS (level 0)?

我相信甚至不可能提供这种服务,因为TCP协议将负责重新传输丢失的消息.对于打算在非TCP,不可靠网络上运行的MQTT-SN来说,这很有意义.

I believe it's not even possible to provide that, since the TCP protocol will take care of retransmission of lost messages. That would make sense for MQTT-SN which is intended to run over non-TCP, unreliable networks.

(注释:使用TCP协议时,级别1至少一次"没有意义,或者是因为TCP已经包含了此保证,但是在更一般的情况下可能有意义,因为规范指出可以使用其他无损协议)

(remark: Level 1 "at least once" doesn't make sense when using the TCP protocol either because TCP already includes this guarantee, but might make sense in a more general case since the spec says other lossless protocol may be used)

推荐答案

严格来说,在TCP/IP层上确认TCP帧并不一定意味着在应用程序层上需要对数据包进行任何操作已经有效地完成了.

Strictly speaking, a TCP frame being acknowledged at the TCP/IP layer does not necessarily mean that, at the application layer, whatever needed to be done with the packet has effectively been done.

在丢失MQTT QoS 0数据包的情况下,可能发生的情况是TCP数据包将其发送给代理(即,从客户端的角度来看确实是ACK),但是代理在以下时间崩溃:将消息传递给所有订阅的客户端.

In the case of a lost MQTT QoS 0 packet, what could happen is that the TCP packet makes it to the broker (i.e is indeed ACK'd from a client point of view), but the broker crashes in the middle of delivering the message to all the subscribed clients.

假设您有100,000个客户端订阅了MQTT主题–将数据转发到订阅的客户端需要花费一些时间,并且代理可能会在过程的中间死亡.从发布者的角度来看,该消息确实已经发布给了代理,但是确实存在消息丢失,因为某些订阅者将永远不会听到该消息.

Say you have 100,000 clients subscribed to the MQTT topic – forwarding the data to the subscribed clients takes a while and the broker may die in the middle of the process. From a publisher point of view, the message has indeed been published to the broker, but there is message loss indeed, since some subscribers will never ever hear about that message.

这篇关于MQTT QoS的用途/目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆