...
- MQTT clients are connecting with the 'Clean Session' flag set to False
- To receive messages from an MQTT Server, a client establishes a connection and creates subscriptions to the desired topicsWhen a MQTT client connects in a persistent session, 'Clean Session' set to False, all relevant client information on the broker is stored ensuring that subscriptions and messages are retained even when the client is offline.
When a MQTT client connects in a non-persistent session, with 'Clean Sesion' set to True, if the connection between the client and broker is interrupted the client loses its subscriptions and needs to re-subscribe upon reconnection.When a MQTT client connects in a persistent session, 'Clean Session' set to False, all relevant client information on the broker is stored ensuring that subscriptions and messages are retained even when the client is offline.
- MQTT client publishing with the 'Retain' flag set to True
When a client publishes a message with the “retained” flag set to true, the broker retains the message. Consequently, any client subscribing to the corresponding topic will receive the most recent retained message, even if no recent publications have occurred.
...
The chart below summarizes how Quality of Service (QOS), Clean Session flag and Retain Message flag affects what messages are receivedpersisted.
| Retain Message flag | Clean Session flag | Subscribe QOS | Publish QOS | Published Message Always ReceivedPersisted |
|---|
| False | True | 0 | 0 | No |
| False | True | 0 | 1 or 2 | No |
| False | True | 1 or 2 | 0 | No |
| False | True | 1 or 2 | 1 or 2 | No |
| False | False | 0 | 0 | No |
| False | False | 0 | 1 or 2 | No |
| False | False | 1 or 2 | 0 | No |
| False | False | 1 or 2 | 1 or 2 | Yes - all messages |
| True | True | 0 | 0 | Yes - last message only for each unique MQTT topic |
| True | True | 0 | 1 or 2 | Yes - last message only for each unique MQTT topic |
| True | True | 1 or 2 | 0 | Yes - last message only for each unique MQTT topic |
| True | True | 1 or 2 | 1 or 2 | Yes - last message only for each unique MQTT topic |
| True | False | 0 | 0 | Yes - last message only for each unique MQTT topic |
| True | False | 0 | 1 or 2 | Yes - last message only for each unique MQTT topic |
| True | False | 1 or 2 | 0 | Yes - last message only for each unique MQTT topic |
| True | False | 1 or 2 | 1 or 2 | Yes - all messages |
...