I read though the MQTT 5 specs but it didn't answer my questions. I am talking about "4.4 Message delivery retry" of the specs. What happens if your client uses no session (cleanStart = true) and the connection gets lost immediately after sending a QoS 2 PUBLISH packet (no PUBREC was received by the client)?
When a Client reconnects with Clean Start set to 0 and a session is present, both the Client and Server MUST resend any unacknowledged PUBLISH packets (where QoS > 0) and PUBREL packets using their original Packet Identifiers. This is the only circumstance where a Client or Server is REQUIRED to resend messages. Clients and Servers MUST NOT resend messages at any other time.
The specs describe that the client MUST NOT resend the message. So how does MQTT 5 guarantee that the message will be received by the receiver?
Sources:
Clean session set to true means that any unacknowledged messages will be discarded.
By setting it to true the client ID actively say it doesn't care about old messages when it reconnects.
The broker can not guarantee that the message is delivered if the client says it doesn't want it .