PUBREC
Fixed header flags: 0000 – all flags reserved
PUBREC is the first broker response in the QoS 2 four-part handshake: PUBLISH → PUBREC → PUBREL → PUBCOMP. When the broker receives a QoS 2 PUBLISH it stores the packet identifier and responds with PUBREC. The publisher must then send PUBREL. PUBREC in MQTT 5.0 carries a reason code.
Details
PUBREC is part 2 of the QoS 2 exactly-once delivery flow: 1. Client → Broker: PUBLISH (QoS 2) 2. Broker → Client: PUBREC ("I received it, waiting for your release") 3. Client → Broker: PUBREL ("You may deliver it now") 4. Broker → Client: PUBCOMP ("Delivered and packet ID released")
The purpose of the two-phase commit is to ensure exactly-once semantics: After PUBREC: broker stores but has not delivered After PUBREL: broker delivers to subscribers After PUBCOMP: both sides release the packet identifier
If the client disconnects between steps, it retransmits PUBLISH (DUP=1) or PUBREL on reconnect. The broker deduplicates based on packet identifier within the session.
MQTT 5.0 reason codes in PUBREC include 0x00 Success and 0x80+ error codes. If PUBREC carries an error code, the publisher MUST NOT send PUBREL – the QoS 2 flow is aborted.
Fixed Header
| Field | Value |
|---|---|
| Packet type (bits 7–4) | 5 (0101₂) |
| First byte (hex) | 0x50 |
| Flags (bits 3–0) | 0000 – all flags reserved |
| QoS bits apply | No |
| Direction | both |
| Added in | MQTT 3.1 |