MQTT QoS的use/purpose是什么?

What is the use/purpose of MQTT QoS?

我正在研究MQTT协议,规范的第一行似乎有矛盾:

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)有什么意义?

我相信甚至不可能提供这一点,因为 TCP 协议将负责重新传输丢失的消息。这对于旨在 运行 通过 非 TCP、不可靠 网络的 MQTT-SN 来说是有意义的。

(备注:使用 TCP 协议时,级别 1“至少一次”没有意义,因为 TCP 已经包含此保证,但在更一般的情况下可能有意义,因为规范说其他无损协议可能被使用)

严格来说,TCP 帧在 TCP/IP 层被确认并不一定意味着在应用层,任何需要对数据包做的事情都已经有效地完成了。

在丢失 MQTT QoS 0 数据包的情况下,可能发生的情况是 TCP 数据包到达了代理(即从客户端的角度来看确实是 ACK),但代理崩溃了正在向所有订阅的客户端发送消息。

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