gmqtt
gmqtt copied to clipboard
publish() and then disconnect() may result in messages not received by a broker
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?