Skip to content

Commit

Permalink
fix min delay before reconnecting to mqtt server after server initiat…
Browse files Browse the repository at this point in the history
…ed disconnect

Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch.io>
  • Loading branch information
dguggemos committed Aug 2, 2022
1 parent 70dcc42 commit 8201c19
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -340,23 +340,23 @@ private boolean isReconnect() {

private Duration getReconnectDelay(final RetryTimeoutStrategy retryTimeoutStrategy,
final MqttDisconnectSource mqttDisconnectSource) {

final Duration result;
final var retryTimeoutReconnectDelay = retryTimeoutStrategy.getNextTimeout();
if (MqttDisconnectSource.SERVER == mqttDisconnectSource) {
// wait at least the configured duration for server initiated disconnect to not overload the server with reconnect attempts
final var reconnectDelayForBrokerInitiatedDisconnect =
mqttConfig.getReconnectMinTimeoutForMqttBrokerInitiatedDisconnect();
if (0 <= retryTimeoutReconnectDelay.compareTo(reconnectDelayForBrokerInitiatedDisconnect)) {
result = retryTimeoutReconnectDelay;
} else {
result = reconnectDelayForBrokerInitiatedDisconnect;
}
result = max(retryTimeoutReconnectDelay, reconnectDelayForBrokerInitiatedDisconnect);
} else {
result = retryTimeoutReconnectDelay;
}
return result;
}

private static Duration max(Duration d1, Duration d2) {
return d1.compareTo(d2) >= 0 ? d1 : d2;
}

private void enableAutomaticReconnect() {
automaticReconnect.set(true);
}
Expand Down

0 comments on commit 8201c19

Please sign in to comment.