I am new to MQTT and I just learned about the meaning of the QOS level that is decided when a message is published:
I noticed that the subscriber side can also set the "Maximum QOS level they will receive". Quoting from here:
For example, if a message is published at QoS 2 and a client is subscribed with QoS 0, the message will be delivered to that client with QoS 0.
Does this mean that the message might not arrive to the client (QOS 0) despite the fact that publisher sent it with QOS 2?
This might be a big issue among inexperienced developers - for example, the default QOS of the subscribe function in the npm mqtt package is 0! (The default should have been the maximum value 2 in my opinion, i.e. "let the publisher decide the QOS").
MQTT guarantees QoS 1 through a simple ACK mechanism. The publisher will publish the message and wait for the response of the receiver's PUBACK packet. If the PUBACK response is not received within the specified time, the publisher will set the message's DUP to 1 and resend the message.
QoS 0 - at most once There is no guarantee of delivery. The recipient does not acknowledge receipt of the message and the message is not stored and re-transmitted by the sender. QoS level 0 is often called “fire and forget” and provides the same guarantee as the underlying TCP protocol.
Understanding Quality of Service (QoS) MQTT may be a lightweight protocol, but it is used in some of the complex scenarios that demand reliable delivery of messages. Clients can configure different levels of Quality of Service (QoS) to ensure reliable message delivery.
MQTT provides 3 QOS levels- QOS 0 – Once (not guaranteed) QOS 1 – At Least Once (guaranteed) QOS 2 – Only Once (guaranteed)
You are correct, there is no guarantee that a message published at QoS 2 will arrive at a subscriber who is using QoS 0. If it is important for that subscriber to receive the message, they should be using QoS 1 or 2. That is something to decide for any given application.
I would rewrite your definition of QoS 0 as "at most once", i.e. the message will be received or it won't, there isn't a chance of a duplicate.
Regarding default QoS - I think most clients use QoS 0 as the default. I don't see that setting QoS 1 or 2 as the default would help the inexperienced developer, they still need to understand why and what they are doing and to consider the implications on their application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With