Understanding mqtt subscriber qos

Oren picture Oren · Nov 2, 2015 · Viewed 8.1k times · Source

I am new to MQTT and I just learned about the meaning of the QOS level that is decided when a message is published:

  • 0 when we prefer that the message will not arrive at all rather than arrive twice
  • 1 when we want the message to arrive at least once but don't care if it arrives twice (or more)
  • 2 when we want the message to arrive exactly once. A higher QOS value means a slower transfer

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").

Answer

ralight picture ralight · Nov 2, 2015

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.