Search code examples
mqtt

What is the meaning of QoS2 in MQTT


In MQTT I have still problems to understand QoS2. The 4-way handshake is:

  1. message is sent from a sender to the receiver
  2. Receiver answers with PUBREC
  3. Sender answers with PUBLREL
  4. Receiver answers with PUBCOMP

But what happens, when receiver gets message in the first step, but the PUBREC message gets lost?

Then the sender must retry to send the message. In this situation, however, we already have sent the message twice what is what we want to avoid.

So how can we say, that QoS2 guarantees, that a message is sent exactly once? What important feature I'm still missing?


Solution

  • I think you're missing this part from the spec:

    Until [the receiver] has received the corresponding PUBREL packet, the receiver MUST acknowledge any subsequent PUBLISH packet with the same Packet Identifier by sending a PUBREC. It MUST NOT cause duplicate messages to be delivered to any onward recipients in this case [MQTT-4.3.3-10].

    So...the receiver essentially ignores the duplicate PUBLISH packets.