guild icon
Toit
#MQTT Publish on unconnected MQTT Client
Thread channel in help
theHuanter
theHuanter 07/17/2023 12:47 PM
If the my code is calling mqtt.publish on a disconnected MQTT Client (I killed the broker to see what happens) it tries to reconnect using the reconnect strategy (default). During this time a publish might happen, which gets blocked until the MQTT Client has connected and then still sends this message.

Can I set a timeout for a publish to happen?

I moved the publish into a task as well and triggered multiple publish. They all got stuck and have been send once the client came back online. Is there a way to cancel a task after a duration n? (that would be the walkaround for the timout of a publish)
theHuanter
theHuanter 07/17/2023 01:12 PM
I could think of something like that:
task:: publish/Task := task:: client.publish REQUEST_TOPIC payload logger.debug "publish has been send" sleep --ms=2000 publish.cancel
floitsch
floitsch 07/17/2023 02:02 PM
Typically we use with_timeout: ...
floitsch
floitsch 07/17/2023 02:03 PM
so:
with_timeout --ms=5_000: client.publish REQUEST_TOPIC payload
👍1
4 messages in total