Search code examples
mqttqos

MQTT higher QoS on subscriber


If I have a publisher sending a message to my MQTT broker with QoS 1 (at least once delivery) and a subscriber with QoS 2 (exactly once delivery), is it possible for the subscriber to still receive duplicate messages?

My concern is that the publisher could send duplicate messages to the broker (since QoS 1 states that is possible) and then the broker would view them all as different messages and forward all of them on to the subscriber. Is this how MQTT brokers work? Or are they smart enough to realize the duplicate messages received from the publisher are all the same and then just forward one on to the subscriber.


Solution

  • The QoS level is between individual clients and the broker. Subscribers also request a QoS level and the broker grants the subscriber a maximum QoS for a subscription.

    The MQTT Spec for v3.1.1 covers how these different QoS levels relate for your example in section 3.8.4:

    The QoS of Payload Messages sent in response to a Subscription MUST be the minimum of the QoS of the originally published message and the maximum QoS granted by the Server.

    The subscriber might have been granted a maximum of QoS 2 when it subscribed to the topic. But the original publisher uses QoS 1. So the subscriber could receive duplicates of the message that the original publisher sent.