[mqtt] connectionStateChanged(CONNECTED) called twice (#12200)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2022-02-05 08:32:56 +10:00 committed by GitHub
parent 97db73938d
commit 73b805b115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 6 deletions

View File

@ -114,8 +114,6 @@ public abstract class AbstractBrokerHandler extends BaseBridgeHandler implements
}).thenAccept(v -> {
if (!v) {
connectionStateChanged(MqttConnectionState.DISCONNECTED, new TimeoutException("Timeout"));
} else {
connectionStateChanged(MqttConnectionState.CONNECTED, null);
}
});
connectionFuture.complete(connection);

View File

@ -59,19 +59,18 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
@Override
public void connectionStateChanged(MqttConnectionState state, @Nullable Throwable error) {
super.connectionStateChanged(state, error);
// Store generated client ID if none was set by the user
final MqttBrokerConnection connection = this.connection;
String clientID = config.clientID;
if (connection != null && state == MqttConnectionState.CONNECTED) {
String clientID = config.clientID;
if (clientID == null || clientID.isBlank()) {
// Store generated client ID if none was set by the user
clientID = connection.getClientId();
config.clientID = clientID;
Configuration editConfig = editConfiguration();
editConfig.put("clientid", clientID);
updateConfiguration(editConfig);
} else {
publish(config.birthTopic, config.birthMessage, config.birthRetain);
}
publish(config.birthTopic, config.birthMessage, config.birthRetain);
}
}