Concept Flow - MQTT with QoS levels
Client publishes message
Check QoS level
QoS0
Done
Shows how MQTT handles message delivery differently based on QoS levels 0, 1, and 2.
client.publish(topic, message, qos=1) # QoS 1: message sent, waits for PUBACK # Resends if no PUBACK received # Ensures message delivered at least once
| Step | Action | QoS Level | Message State | Acknowledgment | Next Step |
|---|---|---|---|---|---|
| 1 | Client sends message | 0 | Sent once | No ack expected | Done |
| 2 | Client sends message | 1 | Sent once | Wait for PUBACK | If no PUBACK, resend |
| 3 | Client receives PUBACK | 1 | Message acknowledged | PUBACK received | Done |
| 4 | Client sends message | 2 | Sent once | Wait for PUBREC | Send PUBREL after PUBREC |
| 5 | Client receives PUBREC | 2 | Message received by broker | PUBREC received | Send PUBREL |
| 6 | Client sends PUBREL | 2 | PUBREL sent | Wait for PUBCOMP | Wait for PUBCOMP |
| 7 | Client receives PUBCOMP | 2 | Delivery complete | PUBCOMP received | Done |
| 8 | No ack received in QoS1 or QoS2 | 1 or 2 | Resend message or PUBREL | Retry until ack | Repeat steps as needed |
| Variable | Start | After Step 1 | After Step 3 | After Step 5 | After Step 7 | Final |
|---|---|---|---|---|---|---|
| Message State | Not sent | Sent once | Acknowledged (QoS1) | Received by broker (QoS2) | Delivery complete (QoS2) | Done |
| Acknowledgment | None | None | PUBACK received | PUBREC received | PUBCOMP received | Complete |
| Retries | 0 | 0 | 0 | 0 | 0 | 0 or more if no ack |
MQTT QoS levels control message delivery: QoS 0: Send once, no ack, no guarantee. QoS 1: Send, wait PUBACK, resend if needed (at least once). QoS 2: Four-step handshake (PUBREC, PUBREL, PUBCOMP) for exactly once. Higher QoS means more reliability but more overhead.