Closed frankyfish closed 1 year ago
@frankyfish Did you ever find a solution to this problem? I'm seeing something similar in an app I'm developing.
Hi @fblampe & @frankyfish ,
When the client reconnects, the broker will send down pending messages immediately and this may happen between the call to connect
and publishes
.
Here is an example I have with QoS 2 messages:
To avoid this, move the publishes
call above the connect
call:
asyncClient.publishes(MqttGlobalPublishFilter.SUBSCRIBED, subCallback);
asyncClient.connect().get();
asyncClient.subscribe(subscription);
I believe this should resolve the issue. Please let me know if this helps!
Another solution is to call subscribe before connect as described here.
Considering the age of this issue and two solutions are now provided, I'll close out this issue. If any issues remain, feel free to open another issue anytime or contact us in our community forum.
Thanks for pointing this out!
Expected behavior
After performing re-connect and re-subscription to MQTT broker callback is fired each time a new message arrives to the topic the client is subscribed to.
Actual behavior
Whenever connection to MQTT broker is lost and then re-stablished, subscription to the same topic is made (using same client instance), callback is not triggered until
asyncClient.publishes()
is executed once again for it.To Reproduce
Steps
MqttGlobalPublishFilter.SUBSCRIBED
Reproducer code
Consider that an MQTT Broker is running on the same machine, locally. For reproducing the problem I've used HiveMQ3 running in Docker. Whenever the code below had been connected and subscribed to the broker I then disconnected it via HiveMQ's web ui to trigger re-connection & re-subscription logic of the test.
Details
I am a bit confused with the behaviour of
publishes()
, I don't expect that I have to execute it each time i establish a connection, in my understanding whenever I register a consumer for mqtt client instance it should be working unless I destroy the instance of the client.