Skip to content

Commit 070d5f9

Browse files
scb01Karthikeyan
authored andcommitted
Added new method to allow developers to specify clean session (#569)
1 parent 127cc1f commit 070d5f9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManager.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)