Skip to content

Commit 1583129

Browse files
author
Inderjeet Singh
committed
Allow maximum reconnection delay to be configurable
Signed-off-by: Inderjeet Singh <inder123@gmail.com> Signed-off-by: Inderjeet Singh <inder@peel.com>
1 parent b0e3fbb commit 1583129

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ public void onSuccess(IMqttToken asyncActionToken) {
15121512
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
15131513
// @Trace 502=Automatic Reconnect failed, rescheduling: {0}
15141514
log.fine(CLASS_NAME, methodName, "502", new Object[] { asyncActionToken.getClient().getClientId() });
1515-
if (reconnectDelay < 128000) {
1515+
if (reconnectDelay < connOpts.getMaxReconnectDelay()) {
15161516
reconnectDelay = reconnectDelay * 2;
15171517
}
15181518
rescheduleReconnectCycle(reconnectDelay);

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttConnectOptions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class MqttConnectOptions {
8181
private String[] serverURIs = null;
8282
private int mqttVersion = MQTT_VERSION_DEFAULT;
8383
private boolean automaticReconnect = false;
84+
private int maxReconnectDelay = 128000;
8485

8586
/**
8687
* Constructs a new <code>MqttConnectOptions</code> object using the
@@ -133,6 +134,22 @@ public void setUserName(String userName) {
133134
this.userName = userName;
134135
}
135136

137+
/**
138+
* Get the maximum time (in millis) to wait between reconnects
139+
* @return Get the maximum time (in millis) to wait between reconnects
140+
*/
141+
public int getMaxReconnectDelay() {
142+
return maxReconnectDelay;
143+
}
144+
145+
/**
146+
* Set the maximum time to wait between reconnects
147+
* @param maxReconnectDelay the duration (in millis)
148+
*/
149+
public void setMaxReconnectDelay(int maxReconnectDelay) {
150+
this.maxReconnectDelay = maxReconnectDelay;
151+
}
152+
136153
/**
137154
* Sets the "Last Will and Testament" (LWT) for the connection.
138155
* In the event that this client unexpectedly loses its connection to the

0 commit comments

Comments
 (0)