Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use/purpose of MQTT QoS?

Tags:

tcp

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)

like image 734
Pedro Affonso Avatar asked Sep 01 '16 17:09

Pedro Affonso


People also ask

What is MQTT QoS levels?

MQTT supports three QOS levels which are designed to ensure message delivery. QOS 0 – Once (not guaranteed) QOS 1 – At Least Once (guaranteed) QOS 2 – Only Once (guaranteed)

What is MQTT is used for?

MQTT (MQ Telemetry Transport) is a lightweight open messaging protocol that provides resource-constrained network clients with a simple way to distribute telemetry information in low-bandwidth environments.

How many QoS levels are there in MQTT?

There are 3 QoS levels in MQTT: At most once (0) At least once (1) Exactly once (2).

Which MQTT QoS level does exactly once delivery of packet?

QoS 2 – Exactly Once The delivery of message will be organized by the sender and the receiver using packet identifier of native PUBLISH message. The publisher sends the QoS 2 PUBLISH packet to the receiver.


1 Answers

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.

like image 90
kartben Avatar answered Sep 22 '22 11:09

kartben