gmqtt icon indicating copy to clipboard operation
gmqtt copied to clipboard

publish() and then disconnect() may result in messages not received by a broker

Open dawcal opened this issue 3 years ago • 0 comments

Hi.

We have such code (simplified): client = MQTTClient(instance_name, session_expiry_interval=0, clean_session=True) await client.connect(broker_addr) client.publish("theMessage", qos=1, retain=True) # we possibly send here much more messages await asyncio.sleep(4) # wait for publish msgs to be sent; 2 secs is not enough, 4 is enough (update: or not) await client.disconnect() sys.exit(0)

problem is with the sleep; without the sleep, "theMessage" (and/or subsquently sent messsages) is not received by the broker. Recently, sleep with even 4 seconds is not enough. Is there a better way to wait for the queued messages to be received by the broker, before making a disconnect?

dawcal avatar Dec 10 '21 11:12 dawcal