paho.mqtt.java
paho.mqtt.java copied to clipboard
Enhancement Request - Optional fixed automatic reconnect Interval
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;
}
This sounds reasonable, we'll also have to add a flag that prevents the reconnect logic attempting to increment or reset the reconnectInterval if it has been set this way.
Hi James, I will submit a pull request for this in the near future :)
There is already a setting in the connect options: automaticReconnectMaxDelay. If minDelay and MaxDelay are set to the same value, then there will be a fixed reconnect interval.
There is already a setting in the connect options: automaticReconnectMaxDelay. If minDelay and MaxDelay are set to the same value, then there will be a fixed reconnect interval.
see #864