Client stop receiving messages from topics after few hours

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();
  }

Hi @dipanjay ,

It is nice that you are interested in MQTT, please be welcome in our community!

  • Could you please describe your use case and your testing setup?

  • Which Mosquitto broker are you using? Is it an online broker or you are self-hosting it?

  • After you noticed that your client stopped receiving the messages, did you try reconnecting it to the broker? Does the client receive all messages after the reconnection?

Thank you,
Dasha from HiveMQ Team