What is the use/purpose of MQTT QoS?
Asked Answered
J

1

13

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)

Jennajenne answered 1/9, 2016 at 17:49 Comment(0)
H
19

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.

Hundredpercenter answered 1/9, 2016 at 18:1 Comment(2)
And how does MQTT guarantee delivery if the program implementing MQTT crashes in the middle of message delivery to clients? All record of the message is lost on the host at that point.Heretofore
@Heretofore I believe that is where a persistent session would be useful. The MQTT client would store any unacknowledged/unconfirmed QoS 1/2 publishes until the broker comes back online. At that point, another publish attempt would be made.Silverts

© 2022 - 2024 — McMap. All rights reserved.