A SUBACK message is sent by the broker to the client to confirm receipt of a SUBSCRIBE message.
A SUBACK message contains a list of granted QoS levels. These are the levels at which the administrators for the broker permit the client to subscribe to a specific topic name. In the current version of the protocol, the broker always grants the QoS level requested by the subscriber. The order of granted QoS levels in the SUBACK message matches the order of the topic Nnames in the corresponding SUBSCRIBE message.
The table below shows the format of the fixed header.
bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
byte 1 | Message Type (9) | DUP flag | QoS level | RETAIN | ||||
1 | 0 | 0 | 1 | x | x | x | x | |
byte 2 | Remaining Length |
The variable header contains the Message ID for the SUBSCRIBE message that is being acknowledged. The table below shows the format of the variable header.
bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
byte 1 | Message ID MSB | |||||||
byte 2 | Message ID LSB |
The payload contains a vector of granted QoS levels. Each level corresponds to a topic name in the corresponding SUBSCRIBE message. The order of QoS levels in the SUBACK message matches the order of topic name and Requested QoS pairs in the SUBSCRIBE message. The Message ID in the variable header enables you to match SUBACK messages with the corresponding SUBSCRIBE messages.
The table below shows the Granted QoS field encoded in a byte.
bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Reserved | Reserved | Reserved | Reserved | Reserved | Reserved | QoS level | ||
x | x | x | x | x | x |
The upper 6 bits of this byte are not used in the current version of the protocol. They are reserved for future use.
The table below shows an example payload.
Granted QoS | 0 |
Granted QoS | 2 |
The table below shows the format of this payload.
Description | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|---|
Requested QoS | |||||||||
byte 1 | Granted QoS (0) | x | x | x | x | x | x | 0 | 0 |
Granted QoS | |||||||||
byte 2 | Granted QoS (2) | x | x | x | x | x | x | 1 | 0 |