In MQTT I have still problems to understand QoS2. The 4-way handshake is:
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?
I think you're missing this part from the spec:
Until [the receiver] has received the corresponding
PUBREL
packet, the receiver MUST acknowledge any subsequentPUBLISH
packet with the same Packet Identifier by sending aPUBREC
. 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.