CAMEL-23352: Add syncOptimisticRetry option to Aggregate EIP#22769
CAMEL-23352: Add syncOptimisticRetry option to Aggregate EIP#22769code-massel wants to merge 3 commits intoapache:mainfrom
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
when you add new options to EIPs you generally need to rebuild the entire code base |
|
for example run from root |
When optimisticLocking is enabled, retries are normally scheduled asynchronously on a background ScheduledExecutorService, which switches threads and breaks transactional use cases where the aggregation repository and inbound message store must commit/rollback within a single transaction boundary. The new syncOptimisticRetry flag (default false) causes the retry delay to execute via Thread.sleep on the calling thread instead, preserving the transaction context. This restores the Camel 2.x behavior for users who need it, without changing the default async behavior.
gnodet
left a comment
There was a problem hiding this comment.
Review: CAMEL-23352 — Add syncOptimisticRetry option to Aggregate EIP
Thank you for this contribution! The use case is well-motivated — async optimistic locking retries breaking transaction context is a real problem, and adding an opt-in synchronous retry is a clean approach. The core implementation logic is correct.
A few items need attention before this can merge.
Blocker: Missing generated files
The PR modifies 4 hand-written files but does not include any regenerated downstream artifacts. CI will fail at the "Fail if there are uncommitted changes" step. Please run:
mvn install -B -pl core/camel-core-model -DskipTestsThen check git status and commit all generated file changes. This will update at minimum:
core/camel-core-model/src/generated/— JSON model metadata, configurersdsl/camel-yaml-dsl/— YAML DSL schema and deserializers
The auto-generated options table in the aggregate EIP docs (aggregate-eip.adoc) will also pick up the new option from the Javadoc after regeneration, so a separate prose change is likely not needed.
Implementation
The core retry logic is sound:
- The
syncOptimisticRetrybranch correctly callsdoDelay(attempt)thencontinues the retry loop on the calling thread. InterruptedExceptionhandling correctly restores the interrupt flag and propagates viaexchange.setException().- Default (
false) preserves existing async behavior — no regression risk. - The reifier and copy constructor correctly wire the new option.
See inline comments for minor suggestions.
Claude Code on behalf of Guillaume Nodet
Rename syncOptimisticRetry → optimisticLockingSyncRetry for consistency with the existing optimisticLocking option naming. Update Javadoc to note the flag only takes effect when optimisticLocking() is enabled. Add tests for non-zero retry delay and thread interruption scenarios. Regenerate catalog metadata.
|
Thanks for the review! I've addressed your feedback in the latest push:
Let me know if there's anything else to adjust |
| sender.start(); | ||
|
|
||
| // Let at least one retry attempt happen before interrupting | ||
| Thread.sleep(100); |
There was a problem hiding this comment.
Can you use Awaitility instead of this Thread.sleep?
|
There are some uncommitted changes: |
When optimisticLocking is enabled, retries are normally scheduled asynchronously on a background ScheduledExecutorService, which switches threads and breaks transactional use cases where the aggregation repository and inbound message store must commit/rollback within a single transaction boundary.
The new syncOptimisticRetry flag (default false) causes the retry delay to execute via Thread.sleep on the calling thread instead, preserving the transaction context. This restores the Camel 2.x behavior for users who need it, without changing the default async behavior.
Description
When
optimisticLockingis enabled on the Aggregate EIP, retry failures are scheduled asynchronously on a backgroundScheduledExecutorService. This thread switch breaks transactional use cases where the aggregation repository and inbound message store must commit/rollback within a single transaction boundary (transaction context is bound to the originating thread).This PR adds a new
syncOptimisticRetryoption (defaultfalse) to theaggregateEIP. When enabled, the retry delay runs viaThread.sleepon the calling thread instead of scheduling on a background executor, preserving the transaction context. Default isfalseso existing routes are unaffected.Target
mainbranch)Tracking
Apache Camel coding standards and style
I checked that each commit in the pull request has a meaningful subject line and body.
I have run
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.