Hi all,
I’m facing an issue while communicating to the broker from the client. After a successful connection with the Mosquitto broker, the client publishes and receives the data successfully. After a couple of hours, the client stops receiving messages from subscribed topics automatically but it can publish the data and even tried with keepalive. Below I’m pasting the snippet of code for connecting to the broker. Thanks
public static HiveMqService buildAndConnectHiveClient() {
client =
MqttClient.builder()
.useMqttVersion5()
.identifier(UUID.randomUUID().toString())
.automaticReconnectWithDefaultConfig()
.addConnectedListener(
context -> {
logger.info("connected - {} - {}", LocalTime.now(), client.toString());
})
.addDisconnectedListener(
context ->
logger.error("disconnected - {} - {}", LocalTime.now(), client.toString()))
.serverHost(Application.applicationProperties.getMqttHost())
.serverPort(Application.applicationProperties.getMqttPort())
.buildAsync();
client
.connect(Mqtt5Connect.builder().noKeepAlive().noSessionExpiry().build())
.whenComplete(
(mqtt5ConnAck, throwable) -> {
if (throwable != null) {
logger.error(
" --- connectClient --- {} :: {}",
throwable.getMessage(),
throwable.getStackTrace());
} else {
var reasonCode = mqtt5ConnAck.getReasonCode();
logger.info("-- mqttClient --- reason :: {}", reasonCode.name());
}
});
return new HiveMqService();
}