-
Notifications
You must be signed in to change notification settings - Fork 102
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
Recommended pattern for "clean start first only" #219
Comments
I haven't seen that implemented anywhere, but it does seem like it would be a nice feature. Which library has it? I'd like to maintain some consistency when possible. The only thing I find is talk of adding it to the mosquitto client, but it looks like that issue is still open. I'm curious about the use case, though. If the program/board/system were to crash and restart, you want to clear the persistent session, but not if the network goes down? Most of the auto reconnect functionality is handled by the underlying Paho C library, so we would need to add the functionality there and wrap it, with a few mods necessary here. We can put a feature request up there. The connect options are cached in the client, and there was a recent request to expose them publicly so that applications don't need to keep their own copy. (The request may have been in the C++ library, but I'm trying to keep them roughly equivalent). But you're essentially correct. The way to do this is to detect the disconnect and just call The RPC math server might be a good one. With RPC's I can actually see wanting to clear any old requests from the persistent session when starting up, but then maintaining them while running, even if there are short network drops. That makes sense. |
Paho for Python has the feature, and, in fact, it is the default setting if not specified by the user. Quite useful, I've found.
Precisely. We're writing long-running applications that are not expected to not crash or stop until a session is complete but are expected to experience varying levels of network reliability. To follow up on how it might work, would it be possible to get an example showing the manual connect being done via connection loss callback? I apologize, but I'm fairly new to Rust, and I've been struggling to get a |
You can move a value into a closure. In this case, just be sure to move a clone of the options into the closure, because you still need them for the initial connect.
This is a little "trick" to use a code block around the closure to create local clones that use the same name as the original value to keep names simple, But in the next release, you shouldn't need to do this, because I'll let you get a reference to the connect options that the client is holding, so you can just get and clone those in the callback:
But there's an important limitation here.... You can't block in a callback So you can't call
The dyn_subscribe.rs example shows connection callbacks. Personally I'm starting to view callbacks as a legacy API, and am moving to just async and streams in my own applications. (Remember the library with callbacks predates async/await by a few years). |
I'm actually doing exactly what you suggest already, and I'm getting the following error:
My understanding is that An investigation of the source code suggests that Source code that won't compile below:
Also, do you have a rough timeline for your next release? I would love to use that new feature you mentioned. It would be significantly easier for my purposes. |
Oops. So sorry. I realized my mistake as I was writing the example, but I got distracted by the kid and didn't fix it. The error is not complaining about moving the options into the closure, but rather moving the variable out of the closure! The The line in the closure should be:
So, all together:
|
Paho libraries in other languages I have used support a clean start for the client being set to "first only" (i.e. clean start the first connect, but if connection is lost, it will restore connection without a clean start and keep subscriptions intact, as well as receive missed messages) It does not appear to me that the Rust implementation has this feature, and as a result, this also makes automatic reconnect, as well as the reconnect APIs rather unusable for my purposes.
What are the recommended patterns for implementing this functionality? I do not see any samples that demonstrate it. As far as I can tell the most viable pattern one would be to use the message stream to detect a disconnect and invoke
connect()
again using a cloned and modifiedConnectionOptions
, but are there alternative recommendations or patterns? (this approach is not ideal for my application structure)The text was updated successfully, but these errors were encountered: