@@ -160,6 +160,9 @@ public class AWSIotMqttManager {
160160 private boolean userDisconnect ;
161161 /** Do we need to resubscribe upon reconnecting? */
162162 private boolean needResubscribe ;
163+
164+ /** Is this a clean Session with no state being persisted from a prior session */
165+ private boolean cleanSession = true ;
163166 /**
164167 * Indicates whether metrics collection is enabled.
165168 * When it is enabled, the sdk name and version is sent with the mqtt connect message to server.
@@ -540,6 +543,16 @@ public void setAutoResubscribe(boolean enabled) {
540543 needResubscribe = enabled ;
541544 }
542545
546+
547+ /**
548+ * Set to true if the connection should be established with a clean session, false otherwise.
549+ * By default, this is set to true.
550+ * @param cleanSession
551+ */
552+ public void setCleanSession (boolean cleanSession ) {
553+ this .cleanSession = cleanSession ;
554+ }
555+
543556 /**
544557 * Constructs a new AWSIotMqttManager.
545558 *
@@ -764,8 +777,7 @@ private void mqttConnect(MqttConnectOptions options,
764777 final AWSIotMqttClientStatusCallback statusCallback ) {
765778 LOGGER .debug ("ready to do mqtt connect" );
766779
767- // AWS IoT does not currently support persistent sessions
768- options .setCleanSession (true );
780+ options .setCleanSession (cleanSession );
769781 options .setKeepAliveInterval (userKeepAlive );
770782
771783 if (isMetricsEnabled ()) {
@@ -884,7 +896,7 @@ void reconnectToSession() {
884896
885897 final MqttConnectOptions options = new MqttConnectOptions ();
886898
887- options .setCleanSession (true );
899+ options .setCleanSession (false );
888900 options .setKeepAliveInterval (userKeepAlive );
889901
890902 if (mqttLWT != null ) {
0 commit comments