Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

tcp - What is the use/purpose of MQTT QoS?

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...