-
Notifications
You must be signed in to change notification settings - Fork 412
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
Update ControllerApiMqttImpl.java to reconnect on Connection Failure #2525
Conversation
After the initial connection attempt in the activate method, we schedule the attemptConnect method to be called periodically every 60 seconds. This ensures that if the MQTT client becomes disconnected for any reason (e.g., network issues, broker restarts), the system will automatically attempt to re-establish the connection at regular intervals.
It's surprising to me, that we have to go such a "hacky" approach. If we have to go that way, I would make |
Yes, thats true. The Connection is retried once and not contiously.
I understand where you're coming from, @sfeilmeier, but I'd like to offer a different perspective: By initializing the ScheduledExecutorService in the activate() method, we gain the flexibility to adjust to configuration changes dynamically. This approach allows for finer control over how resources are allocated, which is essential given the inherently dynamic nature of OSGi services. |
Thank you for the detailed explanation.
This would only be true if we implemented a Maybe we can agree on the approach that we took for "DebugCycleExecutor", combining constructor and activate() method: https://github.com/OpenEMS/openems/blob/develop/io.openems.backend.core/src/io/openems/backend/core/debugcycle/DebugCycleExecutor.java#L48-L53 For terminating, you can use the existing ThreadPoolUtils method: |
Enhanced Lifecycle Management: Modified the component's initialization and shutdown processes. The ScheduledExecutorService, responsible for managing reconnection attempts, is now initialized in the component's constructor and configured in the @activate method. This ensures that the executor is ready for use immediately and adapts to configuration updates. Graceful Shutdown: Implemented a more graceful shutdown process using ThreadPoolUtils.shutdownAndAwaitTermination in the @deactivate method. This approach ensures that ongoing reconnection attempts are properly completed before the component is deactivated, preventing potential resource leaks. Configuration Update Handling: Introduced a @Modified method to dynamically handle configuration changes. This method allows the component to adjust its behavior, such as changing the reconnection attempt interval, without needing to be fully deactivated and reactivated.
Dynamic Reconnection Interval: Added a new configuration parameter (reconnectionAttemptInterval) to the Config interface. This parameter allows users to specify the interval between reconnection attempts to the MQTT broker, enhancing the component's adaptability to network conditions or broker availability.
@sfeilmeier should be applied now ? Dynamic Reconnection Interval: Added a new configuration parameter (reconnectionAttemptInterval) to the Config interface. This parameter allows users to specify the interval between reconnection attempts to the MQTT broker, enhancing the component's adaptability to network conditions or broker availability. Enhanced Lifecycle Management: Modified the component's initialization and shutdown processes. The ScheduledExecutorService, responsible for managing reconnection attempts, is now initialized in the component's constructor and configured in the @activate method. This ensures that the executor is ready for use immediately and adapts to configuration updates. Graceful Shutdown: Implemented a more graceful shutdown process using ThreadPoolUtils.shutdownAndAwaitTermination in the @deactivate method. This approach ensures that ongoing reconnection attempts are properly completed before the component is deactivated, preventing potential resource leaks. Configuration Update Handling: Introduced a @Modified method to dynamically handle configuration changes. This method allows the component to adjust its behavior, such as changing the reconnection attempt interval, without needing to be fully deactivated and reactivated. What do you think about my approach? |
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
io.openems.edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/Config.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
@sfeilmeier maybe now everything is fixed i guess - if i forgot something just hit me up :) |
Some news on this topic? |
up |
After the initial connection attempt in the activate method, we schedule the attemptConnect method to be called periodically every 60 seconds. This ensures that if the MQTT client becomes disconnected for any reason (e.g., network issues, broker restarts), the system will automatically attempt to re-establish the connection at regular intervals.
See Issue here