Skip to content

CAMEL-24382: camel-azure-cosmosdb - process change-feed batches synchronously so events are not lost on failure - #25636

Open
oscerd wants to merge 1 commit into
apache:camel-4.22.xfrom
oscerd:backport/CAMEL-24382-4.22.x
Open

CAMEL-24382: camel-azure-cosmosdb - process change-feed batches synchronously so events are not lost on failure#25636
oscerd wants to merge 1 commit into
apache:camel-4.22.xfrom
oscerd:backport/CAMEL-24382-4.22.x

Conversation

@oscerd

@oscerd oscerd commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Backport of #25617 (CAMEL-24382) to camel-4.22.x.

The bug

The camel-azure-cosmosdb change-feed consumer processed each batch with a fire-and-forget async
callback (getAsyncProcessor().process(exchange, EmptyAsyncCallback.get())). Azure's
ChangeFeedProcessor advances (checkpoints) the lease as soon as the event handler returns, so the
lease could move past a batch before processing finished — and if processing then failed, those
events were silently lost.

The fix

Process each batch synchronously and rethrow on failure as a RuntimeCamelException, so the
handler only returns normally once the exchange has completed. On failure the lease is not advanced
and the batch is redelivered on the next feed poll (at-least-once) instead of being dropped.

Backport notes

  • Clean cherry-pick of the merged main commit (4e94d720ec40); no code adaptation was required
    (camel-4.22.x already uses camel-test-junit6, like main).
  • Verified locally: full-reactor install -DskipTests is green and CosmosDbConsumerTest passes
    (2 tests), with no generated-file drift.

Claude Code on behalf of @oscerd

…ronously so events are not lost on failure (apache#25617)

CosmosDbConsumer.onEventListener dispatched the exchange fire-and-forget
(getAsyncProcessor().process(exchange, EmptyAsyncCallback.get())) and returned
immediately. The Azure SDK ChangeFeedProcessor uses a synchronous
handleChanges handler and advances (checkpoints) the lease as soon as that
handler returns - i.e. before the route processed the batch. On a route
failure the lease had already advanced, so the batch was never redelivered and
the change feed silently lost data (at-most-once).

Process the batch synchronously and rethrow on failure, so the lease is only
checkpointed after successful processing and a failed batch is redelivered on
the next feed poll (at-least-once). The processing is extracted into a
package-private processBatch(Exchange) seam covered by CosmosDbConsumerTest
(failure rethrows, success returns normally).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
(cherry picked from commit 4e94d72)
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-azure/camel-azure-cosmosdb

🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all tested

Maveniverse Scalpel detected 38 affected modules (current approach: 9).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 9 modules (1 direct + 8 downstream), skip tests for 29 (generated code, meta-modules)

Modules Scalpel would test (9)
  • camel-azure-cosmosdb
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (38 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Azure :: CosmosDB
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants