-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Mqtt V5 improve automaticReconnect #3822
Comments
If such a behavior is not available in the Paho client, then I'm not sure what would you expect from us to here in our channel adapters.
so, if we fail to start/connect we emit that
Does it make sense? |
Thanks for your answer. I was thinking of something similar to what is done in the MQTT V3 channel adapters, where a scheduler is started when connection fails on startup: Line 183 in e855f13
Concerning the documentation, I was thinking of adding a disclaimer in this part of the documentation: https://docs.spring.io/spring-integration/docs/current/reference/html/mqtt.html#mqtt-v5.
|
Yeah... I see your point now having that opened issue in Paho client if it fails to connect originally, it does not retry. Let us know if you are willing to contribute the fix: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc ! |
I had a look at Paho Client implementation. The reconnect() will launch the scheduler. By calling this method once the behaviour will be as expected.
I'm willing to contribute |
Thanks, @kroutal ! Indeed the Paho Client does not move the connection to the proper state on a first attempt.
to call the mentioned
It was not connected before and it is really not disconnecting at the moment. So, according to your investigation it is really correct to call the mentioned So, it really would be great if you can contribute the fix and we will continue discuss details already in code. |
…onnection fails
Fixes: #3822 * Apply spring-framework code style on modified class * Remove unwanted formatting * Take pull request comments into account * Code and JavaDocs clean up * Improve `Mqttv5BackToBackAutomaticReconnectTests` removing non-related code * Improve `mqtt.adoc` for this new manual reconnection feature **Cherry-pick to `5.5.x`**
Fixes spring-projects#3685 Other fixes and improvements after code review: * Get manual `reconnect` invocation back for v3/v5 adapters and client managers (see bug spring-projectsGH-3822 for a reasoning) * Remove unnecessary getters/setter for a listener and use adapter class as listener instead * Optimize MessageListener: remove redundant inner class and use a single method reference instead of N instances per each subscribe * Javadocs improvements
Fixes #3685 Introduce some initial design. Add a new interface `ClientManager` which will manage clients and connections. Use this manager in v3 topic adapter and message handler. Add a new interface `ClientManager` which will manage clients and connections. Add different implementations for v3 and v5 MQTT clients. Use this manager in v3/v5 topic adapters and message handlers. Add a couple of unit/integration tests to cover client manager usage. Several small code improvements after the code review: * Improve client manager usage via providing several mutual exclusive constructors, whether the users provides `url` or `connectionOptions` or `clientFactory` for v3. * Move the logger to `AbstractMqttClientManager` * Do not inject TaskScheduler in constructor for v3 client manager but use lazy init via `BeanFactory` and `IntegrationContextUtils` * Other smaller code readability improvements Add new tests with reconnect cases. Other code improvements after the code review: * Adjust javadocs according to standards * Remove `setClientManager` and use exclusive ctors * Make automatic reconnects using the v3 client instead of manually using task scheduler Some fixes and improvements after another code review iteration: * Rearrange the code according to the code style guides * Move client instance to `AbstractClientManager` with `isRunning` method * Fix abstract adapter/handler fields visibility and `final`ize them where we can * Send application event if automatic reconnect is not enabled for the client manager Other fixes and improvements after code review: * Changes around fields, methods, ctors visibility * Removed contradictory ctors * Reduce amount of unnecessary `getClientManager() != null` checks in logic and make it as similar as possible for client manager and the old approach * Use auto-reconnect where possible * Remove manual reconnect trigger and rely on events instead to know where to subscribe * Do not close the connection in adapter to be able to use reconnect logic without lose of subscriptions * Make `ClientManager` extend `MqttComponent` so that it knows about connection options as part of its contract * Remove not relevant auto test cases (relying on connection close or manual reconnect) * Other code style smaller changes Other fixes and improvements after code review: * Get manual `reconnect` invocation back for v3/v5 adapters and client managers (see bug GH-3822 for a reasoning) * Remove unnecessary getters/setter for a listener and use adapter class as listener instead * Optimize MessageListener: remove redundant inner class and use a single method reference instead of N instances per each subscribe * Javadocs improvements * Add Javadocs to abstract client manager * Extract common callback add/rm logic to abstract adapter class * Small code cleanups/fixes related to code style & simplicity, ctor inits and unnecessary methods; eliminate unnecessary logs noise * Remove `@LongRunningTest` for `ClientManagerBackToBackTests` as test run time is ~6-7 secs * Remove client factory as dependency for v3 client manager and use plain connection properties and client persistence instead * Add missed javadocs * Other code style & cleanup improvements * More code cleanup * More Javadocs
Expected Behavior
Mqtt V5 automaticReconnect should work when first connection fails.
This is related to : eclipse/paho.mqtt.java#930
Current Behavior
When application starts and server is down or something goes wrong during connection then In Mqttv5PahoMessageHandler/Mqttv5PahoMessageDrivenChannelAdapter there will never be a reconnection attempt even though automaticReconnect is set to true
Context
The only way to reconnect is to add a MqttConnectionFailedEvent listener. And recode the reconnection mechanism using Timers.
If this is the intended behavior then it should be documented.
The text was updated successfully, but these errors were encountered: