Android app Hivemq client if subscribe same topic multiple times

Android app Hivemq client if subscribe same topic multiple times ,what will happen? i want to subscribe only once.but when i subscribe topic only once after login …some messages not received and some received . any possible solution ? i am checking every time ,client connection is connected.(not disconnected) help needed urgently…

Hi @kalpana,

Could you please provide the code when you connect/reconnect? My guess is that something with the session of the client causes the issue you describe.

Possible problems:

  • you have a low session expiry, meaning the session (the state for the client) of the client on the broker does expire if client is not connected for a long time
  • you use cleanStart=true when connecting, this would overwrite the previous session of the client

Greetings,
Michael

hi,
Thanks for quick reply.

private Connection (Context context) {
//Instantiate the mqtt android client class
mqttAndroidClient = Mqtt3Client.builder()
.identifier(UUID.randomUUID().toString())
.serverHost(“server address”)

            .serverPort(1883)
            .automaticReconnectWithDefaultConfig()

            .buildAsync();
      
    mqttAndroidClient.toAsync().connect()
            .whenComplete((Mqtt3ConnAck, throwable) -> {
                if (throwable != null) {
                    // Handle connection failure
                    android.util.Log.v("HIVE-MQTT", "Client connection failed");
                } else {
                    // Setup subscribes or start publishing

                    android.util.Log.v("HIVE-MQTT", "Client connected");
                    connected = true;
                }
            });
}

}

created connection after login successful and then subscribing topic . In parent Activity after every 5 min i am checking connection is available or not.
after login geting messages in callback smoothly…then after sometime going forward and backward on other activities messages not received in callback. …

Hi @kalpana,

changing

mqttAndroidClient.toAsync().connect()

to

mqttAndroidClient.toAsync().connectWith().cleanSession(false).send()

should fix your problem. As the hivemq-client connects without persistent session as default.

Greetings,
Michael

@michael_w thank you. this solved my problem. now Android client received all messages without loosing any message in between.

Glad to hear, happy coding :slight_smile:

Greetings,
Michael