Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reconnection failure upon network disconnect(Issue#584) #612

Merged
merged 5 commits into from
Dec 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ public class AWSIotMqttManager {
private static final Integer MILLIS_IN_ONE_SECOND = 1000;

private static final Log LOGGER = LogFactory.getLog(AWSIotMqttManager.class);
/** Constant for number of tokens in endpoint. */
private static final int ENDPOINT_SPLIT_SIZE = 5;
/** Constant for token offset of "iot" in endpoint. */
private static final int ENDPOINT_IOT_OFFSET = 1;
/** Constant for token offset of "amazonaws" in endpoint. */
private static final int ENDPOINT_DOMAIN_OFFSET = 3;
/** Constant for token offset of "com" in endpoint. */
private static final int ENDPOINT_TLD_OFFSET = 4;

/** Default value for starting delay in exponential backoff reconnect algorithm. */
public static final Integer DEFAULT_MIN_RECONNECT_RETRY_TIME_SECONDS = 4;
Expand Down Expand Up @@ -550,10 +542,11 @@ public void setAutoResubscribe(boolean enabled) {
needResubscribe = enabled;
}


/**
* Set to true if the connection should be established with a clean session, false otherwise.
* By default, this is set to true.
* By default, this is set to true. AWS IoT message broker currently does not support persistent sessions
* (connections made with the cleanSession flag set to false). Support for persistent sessions
* (setting cleanSesssion to false) may be supported in the future.
* @param cleanSession flag to establish a clean session
*/
public void setCleanSession(boolean cleanSession) {
Expand Down Expand Up @@ -938,7 +931,7 @@ void reconnectToSession() {

final MqttConnectOptions options = new MqttConnectOptions();

options.setCleanSession(false);
options.setCleanSession(cleanSession);
options.setKeepAliveInterval(userKeepAlive);

if (mqttLWT != null) {
Expand All @@ -962,7 +955,7 @@ void reconnectToSession() {

try {
final String mqttWebSocketURL = signer
.getSignedUrl(endpoint, clientCredentialsProvider.getCredentials(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment on why this being changed from "endpoint" to "endpointWithHttpPort"?

.getSignedUrl(endpointWithHttpPort, clientCredentialsProvider.getCredentials(),
System.currentTimeMillis());
LOGGER.debug("Reconnect to mqtt broker: " + endpoint + " mqttWebSocketURL: " + mqttWebSocketURL);
// Specify the URL through the server URI array. This is checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,8 @@
*/
public final class AwsIotEndpointUtility {

/** Constant for token offset of user's account prefix in endpoint. */
private static final int ENDPOINT_PREFIX_OFFSET = 0;
/** Constant for token offset of "iot" in endpoint. */
private static final int ENDPOINT_IOT_OFFSET = 1;
/** Constant for token offset of AWS region in endpoint. */
private static final int ENDPOINT_REGION_OFFSET = 2;
/** Constant for token offset of "amazonaws" in endpoint. */
private static final int ENDPOINT_DOMAIN_OFFSET = 3;
/** Constant for token offset of "com" in endpoint. */
private static final int ENDPOINT_TLD_OFFSET = 4;
/** Constant for token offset of "cn" in endpoint*/
private static final int ENDPOINT_CN_TLD_OFFSET = 5;
/** Constant for number of tokens in endpoint. */
private static final int ENDPOINT_SPLIT_SIZE = 5;
/** Constant for number of tokens in China's endpoint. */
private static final int ENDPOINT_CN_SPLIT_SIZE = 6;
/** Constant for number of tokens in China's ATS endpoint. */
private static final int ENDPOINT_CN_ATS_SPLIT_SIZE = 7;

Expand Down