fluffysquirrels / mqtt-async-client-rs

An MQTT client written in Rust
MIT License
40 stars 16 forks source link

Keep publishing and automatic reconnect #17

Closed amrx101 closed 3 years ago

amrx101 commented 4 years ago

I have a use case where in

The first one, we can use a loop, but on the second , how do we handle reconnect with a loop. What kind of error does the client throw if disconnection happens.

cs2dsb commented 4 years ago

From the docs you can see Client.publish (and other methods) returns a crate::Result with the error part crate::Error which includes a Disconnected variant.

You'll need to check if publish (or any other methods your use) return this result and handle the errors appropriately. Likely you can just try reconnecting for any kind of error assuming the very first connect worked ok. There may be some StdError variants that are actually fatal OS issues but what you do with those I couldn't say.

fluffysquirrels commented 3 years ago

Closing due to inactivity, I think @cs2dsb gave a sufficient response.