The most common reason for excessive memory usage at an MQTT Server is that messages are being stored at the MQTT Server for future delivery.
There are two reasons messages are stored at an MQTT Server:
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 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 persisted.
Retain Message flag | Clean Session flag | Subscribe QOS | Publish QOS | Published Message Persisted |
---|---|---|---|---|
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 |
The Chariot UI will display MQTT Client details under MQTT > Client Status including the Clean Session flag, the subscribe QOS and all Retained Messages.
By default MQTT Distributor com.cirruslink.chariot.server.core.PacketHandler will log each MQTT client connection indicating the 'Clean Session' flag as shown below:
A [C] in this message indicates Clean Session = True whilst a [P] indicates Clean Session = False
By default MQTT Distributor com.cirruslink.chariot.server.core.PacketHandler will log each MQTT client subscription as shown below:
The [] after the topic subscription indicates the quality of service. For example:
Retained messages are currently not available to view in MQTT Distributor