eclipse-paho / eclipse-paho/paho.mqtt.java

Enhancement Request - Optional fixed automatic reconnect Interval

Open
#276 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

Please fill out the form below before submitting, thank you!
- [x] Bug exists Release Version 1.1.0 ( Master Branch)
- [x] Bug exists in Snapshot Version 1.1.1-SNAPSHOT (Develop Branch)

Currently, the reconnect interval starts from 1 second, then double the previous interval in the next attempt, with the max interval of 2 minutes. This implement works nicely for short interruption of network connectivity, but it does not work well for devices move between networks (e.g. cellular to WIFI) or in and out of a network. When the network layer and security settle, it is desirable to reconnect to the MQTT broker as soon as possible instead of the maximum 2-minute interval.

I am proposing an option to allow the application to set a fixed reconnect interval. If this option is not specified, the default behavior is the same as before.

```
/**
* Sets the reconnect interval.
* This value, measured in seconds, defines the time interval
* the client will attempt to reconnect.
* The default behavior is the client will attempt to reconnect at one second
* and double the interval on the next attempt.
* A value of 0 meaning the client will use the default behavior.
* @param reconnectInterval the time interval value, measured in seconds. It must be >0;
*/
public void setAutomaticReconnectInterval(int reconnectInterval) {
if (reconnectInterval < 0) {
throw new IllegalArgumentException();
}
this.automaticReconnectInterval = reconnectInterval;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.