HiveMQ

MQTT Disconnect and Reconnects at very short intervals for Android Client

I’m trying to connect mqtt broker with fixed clientID, it’s working fine but with several reconnect client disconnect and reconnect at very short intervals. Initializing connection from Android service onCreate and cleanup in onDestroy method.

//client builder
MqttClientBuilder builder = MqttClient.builder()
.identifier(identifier)
.serverHost(brokerAddress)
.serverPort(port)
.addDisconnectedListener(new MqttClientDisconnectedListener() {
@Override
public void onDisconnected(@NotNull MqttClientDisconnectedContext context) {
Log.e(“hive”,"disconnected " + context.getSource().toString());
context.getCause().printStackTrace();
}
})
.addConnectedListener(new MqttClientConnectedListener() {
@Override
public void onConnected(@NotNull MqttClientConnectedContext context) {
Log.e(“hive”,“connected”);
}
})
.automaticReconnectWithDefaultConfig();

client = builder
        .useMqttVersion3()
        .buildBlocking();