When i run my code it's working fine but after some hours it stop working and show this error Not able to publish: MQTT client is not connected
public Mqtt5AsyncClient connect(String host, int port) {
Mqtt5AsyncClient client = MqttClient.builder().useMqttVersion5()
.identifier(UUID.randomUUID().toString())
.serverHost(host)
.serverPort(port).buildAsync();
Mqtt5ConnAck connectionAck = null;
try {
connectionAck = client.toBlocking().connect();
Mqtt5ConnAckReasonCode connAckCode = connectionAck.getReasonCode();
logger.debug("Client connected to broker with url: " + host + ":" + port + " ::Connection ack code: " + " keep alive ");
} catch (Exception ex) {
logger.debug("Not able to connect to broker with url: " + host + ":" + port);
ex.printStackTrace();
}
return client;
}