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 =
                context -> {
        "connected - {} - {}",, client.toString());
                context ->
                    logger.error("disconnected - {} - {}",, client.toString()))
            (mqtt5ConnAck, throwable) -> {
              if (throwable != null) {
                    " --- connectClient --- {} :: {}",
              } else {
                var reasonCode = mqtt5ConnAck.getReasonCode();
      "-- mqttClient --- reason :: {}",;
    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