Java – Does the Eclipse Paho Mqtt Client retain all published messages until they are brokered to confirm delivery under QoS-2?

Does the Eclipse Paho Mqtt Client retain all published messages until they are brokered to confirm delivery under QoS-2?… here is a solution to the problem.

Does the Eclipse Paho Mqtt Client retain all published messages until they are brokered to confirm delivery under QoS-2?

Does the default PAHO MQTT implementation keep all messages being pushed until their delivery is specifically confirmed in QoS 2? Or, if not, how do we achieve it ourselves?

Update
Since Paho Android service version 1.1.0, automatic reconnection and offline buffering have been implemented. More information: https://www.eclipse.org/paho/clients/android/

Solution

From javadoc For MqttClient

By default MqttDefaultFilePersistence is used to store messages to a file. If persistence is set to null then messages are stored in memory and hence can be lost if the client, Java runtime or device shuts down.

This means that as long as you set the path correctly and have the correct Android permissions to write to local storage, QOS2 messages should persist until they are delivered to the broker and not to the end subscriber.

Related Problems and Solutions