Hi. I need some help. I am using the Java Class client in order to build a subscriber client that must receive QOS 1 and QOS 2 messages send from a publisher.
The client connects with an async connection, with .cleanStart(false).
The connAck states .isSessionPresent() as true.
Subscription is made with .qos(MqttQos.EXACTLY_ONCE).
But either after ABORTING the client, or CLOSING the connection, whatever message is published with QOS 1 or 2 is lost and not received when connecting the subscriber client again.
I have been messing around with bigger or smaller sessionExpireInterval and keepAlive parameters with no progress.
I will appreciate any help on this subject.
Thanks in advance!
Excellent - welcome back. From the Java MQTT client side, I’m sure this functionality works as it’s a core feature - and we support this extensively when using the HiveMQ broker. So it may likely be an Mosquitto related issue - or at least it’s worth validating.
In the Mosquitto config, double check the max_queued_bytes and max_queued_messages settings.
It sounds like you’re doing everything correctly in the client code, so unfortunately the only option is to use the process of elimination.
With your Mosquitto setup, attempt to replace the Java client by using mosquitto_sub or mqtt-cli and see if the same issue exists. This should tell us a lot - where the problem likely exists - in client code or in broker.
Let me know if I explained this well enough and if you discover something.
Ok great - Then if that’s the case, also make sure that you call subscribe before reconnecting. If not, the queued messages may be sent down before you have a handler setup to handle the incoming messages.
You could verify this by watching the MQTT traffic in tcpdump or Wireshark.