[
https://issues.apache.org/jira/browse/CAMEL-22949?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-22949:
--------------------------------
Fix Version/s: 4.x
> Migrate components from Thread.sleep() to Camel's Task API for retry/backoff
> delays
> -----------------------------------------------------------------------------------
>
> Key: CAMEL-22949
> URL: https://issues.apache.org/jira/browse/CAMEL-22949
> Project: Camel
> Issue Type: Improvement
> Reporter: Guillaume Nodet
> Assignee: Guillaume Nodet
> Priority: Major
> Fix For: 4.x
>
>
> Several Camel components currently use Thread.sleep() for retry delays,
> backoff delays, and reconnection handling. This approach has
> several drawbacks:
> - Poor integration with Camel's lifecycle management
> - Difficult to interrupt during shutdown
> - No consistent task management across components
> - Limited observability and monitoring capabilities
> Following the successful implementation in PR #21209 (CAMEL-22898 - Google
> PubSub), we should migrate other components to use Camel's Task API
> (Tasks.backgroundTask() or Tasks.foregroundTask() with appropriate budgets).
> h2. Benefits
> - Better lifecycle management and graceful shutdown
> - Consistent task management across all components
> - Improved observability through Camel's task framework
> - Proper resource cleanup on failures
> - Sleepless blocking for background tasks
> h2. Components to Update
> h3. High Priority (retry/reconnection logic similar to PubSub):
> # *camel-salesforce* - SubscriptionHelper.java:220 - Uses
> Thread.sleep(backoff) for subscription retry with exponential backoff
> # *camel-aws2-athena* - Athena2QueryHelper.java:166 - Uses
> Thread.sleep(this.currentDelay) for query polling with backoff
> # *camel-zookeeper* - ZooKeeperConsumer.java:177 - Uses
> Thread.sleep(configuration.getBackoff()) for reconnection backoff
> # *camel-hazelcast* - HazelcastSedaConsumer.java:152 - Uses
> Thread.sleep(endpoint.getConfiguration().getOnErrorDelay()) for error
> recovery delay
> # *camel-iggy* - IggyFetchRecords.java:70 - Uses Thread.sleep(1000) to
> avoid busy-waiting when suspended
>
> h3. Medium Priority:
> # *camel-stream* - StreamConsumer.java - Polling delay
> # *camel-irc* - IrcConsumer.java & IrcProducer.java - Reconnection delays
> # *camel-kubernetes* - KubernetesLeadershipController.java - Leadership
> election backoff
> # *camel-jgroups-raft* - JGroupsRaftClusterView.java - Cluster view
> refresh delay
>
> h2. Reference Implementations
> - *camel-google-pubsub* - PR #21209 (CAMEL-22898)
> - *camel-pgevent* - PgEventConsumer.java:72-80 - BackgroundTask for
> reconnection
> - *camel-smpp* - SmppUtils.java:323-336 - Helper method for creating
> reconnect
> h2. Implementation Pattern
> {code:java}
> Tasks.foregroundTask()
> .withBudget(Budgets.iterationBudget()
> .withMaxIterations(1)
> .withInterval(Duration.ofSeconds(delaySeconds))
> .build())
> .withName("ComponentRetryDelay")
> .build()
> .run(getEndpoint().getCamelContext(), () -> true);
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)