-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for automatic reconnect mode #53
Comments
+1 |
I can see this issue opened since more than 2 years and none of the contributors. One of my colleague is constantly facing issue with dropped connections. I went through the src code and to avoid half-open connections , keep alive poll is implemented to send empty packed to broker with ping request to detect dropped connection on the client side. I was wondering if some workaround can be done around keep alive exception raise to reconnect logic to reconnect the client to the broker. I can take up the initiative to add this , but i want some kind of acknowledgement from one of the contributors that i am heading in right direction. |
Hello @ajays871, I would very much welcome a contribution to this - it is a long overdue enhancement. I have had to reject some Pull Requests; here are some things to look out for:
Some things to look out for related to this issue:
Would be great if there was a way of doing a small first step in the right direction... |
Heh... It can handle automatic reconnecting and actually has been running for a few days flawlessly, even surviving full internet outages. I'm really, REALLY new to writing ruby gems, and I bet I am doing some quirky stuff, but ... There is a lot of things that I would love to see being handled in a smoother way (nonblocking code, etc). |
I am struggling to find a way to handle disconnects. Currently an error is raised on parent thread causing problems. |
@parhs, if you want I could put my MQTT Code in a separate repository. The only way I found that allows for complete control over the thrown errors is by not using "MQTT::Client.connect()" directly, but instead creating a new MQTT Client class, and then wrapping every MQTT-Related statement including the connect in a |
@Xasin if you could it could be helpful. The only workaround I found is to use blocking mode and rescue exceptions. However messages could be lost this way. |
@parhs, my implementation is more or less "stand-alone-ish", and I could have probably used a lot more documentation etc., and possibly look at pre-existing event-based systems like For now, you could take the files
You can also use Aside from the occasional |
@parhs, I've finally made my code a gem. YMMV on unstable connections, but with a normal internet connection, I've managed to run my personal smart home code for weeks without needing a restart. @njh, I hope this is something you find interesting and might link it on the Readme. |
Is it dependent of #52 ? |
@Vincent14 no, I don't think so |
Just a heads-up that my MQTT code is still maintained, and has been rewritten to be a bit cleaner now. |
There is also the Paho Ruby MQTT library: |
Paho is nice but it throws various exceptions in normal operation and seems to have some bugs, for example: PahoMqtt::WritingException: Broken pipe Is there any way to detect a connection loss and reconnect with this gem? |
@rgaufman The way I handled it was by doing the subscribe/publishing from separate threads with appropriate begin-rescue wrapping, and adding a bit of manual reconnection. You could try out my MQTT Gem, which just wraps this gem up a little more conveniently, at https://github.com/XasWorks/XasCode/tree/master/Ruby/MQTT |
Interesting, will have a play with it, thank you! |
Hi @njh, maybe it's worth getting some inspiration from the implementation from the Locant MQTT gem as well? It looks promissing to me. Regards, |
No description provided.
The text was updated successfully, but these errors were encountered: