How to implement auto-reconnect in Android?
pravingaikwad07 opened this issue ยท 1 comments
pravingaikwad07 commented
๐ Feature Request
Auto reconnection
๐ Motivation
Is there a way to implement auto reconnect in case of timeout or network issues and restore the lost publish and subscribe events?
๐ฐ Alternatives
๐ Additional context
pglombardo commented
Hi @pravingaikwad07 - apologies for the late reply. To enable auto reconnect, see this example:
final Mqtt5BlockingClient client2 = Mqtt5Client.builder()
.serverHost("broker.hivemq.com")
.automaticReconnect()
.initialDelay(3, TimeUnit.SECONDS)
.maxDelay(10, TimeUnit.SECONDS)
.applyAutomaticReconnect()
.addConnectedListener(context -> System.out.println("connected " + LocalTime.now()))
.addDisconnectedListener(context -> System.out.println("disconnected " + LocalTime.now()))
.buildBlocking();
This example is from here.
This should answer your question. Given the age of this issue I'll close this out. If anything remains, let us know. We'd be more than happy to help out!