What is the use/purpose of MQTT QoS?

故事扮演 提交于 2019-11-29 09:23:15

问题


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

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.

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

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.

(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)


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/39277933/what-is-the-use-purpose-of-mqtt-qos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!