CAMEL-23336: camel-mongodb - Expose Resume Token (Change Streams Consumer)#22674
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
Please run a full mvn clean install -DskipTests from root folder. |
|
you need to build the source code for the entire project as when you add new options there are code changed elsewhere |
Hi, thanks for the info. I think my problem is that I've done the build on Windows and it messed up all the line endings in generated source (over 3k files changed). I've commited the changes inside components/camel-mongodb but that seems not enough. I will try to run the build on linux next week. |
|
Hi @Michwo I think that this feature can be implemented with Camel's resume strategy (ResumeAware Consumer). Using the resume strategy, the Camel route would look like: The resumeToken handling will be offloaded to the framework, and hopefully it will be easier to use. The ResumeAware implementation can be done in another PR, no need to change the current implementation, but please open an issue about it. fyi @orpiske |
|
🧪 CI tested the following changed modules:
Build reactor — dependencies compiled but only changed modules were tested (5 modules)
|
orpiske
left a comment
There was a problem hiding this comment.
Thanks for this contribution. However, I think this this could be implemented using our Resume Strategies API.
Should I then abandon this Issue/PR and try to implement the resume strategy for camel-mongodb? |
I think either way is fine. You are free to pick the way you find more convenient. Personally, I'd prefer to reuse the PR, so we have the history of the conversation (specially because the idea IS good - we'd like to have this on the code - it's just the implementation that needs to be tweaked to fit into what we already have). |
e805484 to
357f397
Compare
…om/Michwo/camel into feat-camel-mongodb-cs-resume-token
|
I've finally found some time to work on that again - I've reimplemented this like @orpiske and @Croway have suggested, as an resume strategy eip. I used the camel-kafka's implementation as a template for this. Changes included:
Startup token priority: resume strategy token first, then endpoint/repository Tests for the added code are included (value/integration). The documentation is also updated to reflect the changes (camel-mongodb and Resume Strategies). |
davsclaus
left a comment
There was a problem hiding this comment.
Nice work adding resume token support to the MongoDB change streams consumer — the dual approach (endpoint-level + resume strategy) is well designed and the test coverage is solid.
Two items worth looking at:
1. doStop() lifecycle ordering (medium): In MongoDbChangeStreamsConsumer.doStop(), the token repository is shut down before the change streams thread is stopped. The thread could still be in the middle of commitManager.commit() → repo.setState() when the repo is already closed. For MemoryStateRepository this is harmless (just a HashMap), but for a persistent StateRepository it could throw or silently drop the final token. Consider stopping the repo after the thread and executor shutdown.
2. PR description mismatch (minor): The description says the resume token is exposed via MongoDBConstants.RESUME_TOKEN, but the code correctly uses Exchange.OFFSET with a MongoDbResumable wrapper (the standard Camel resume pattern). The description should be updated to match.
3. Duplicate test utility (nit): The identical InMemoryStringResumeCache inner class appears in both MongoDbResumeAdapterTest and MongoDbResumeStrategyTest — could be extracted to a shared test helper.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
davsclaus
left a comment
There was a problem hiding this comment.
All feedback from the prior review has been addressed:
doStop()lifecycle ordering — fixed: the token repository is now stopped after the thread and executor shutdown, preventing potential writes to a closed repo.- Duplicate
InMemoryStringResumeCache— extracted to a sharedsupport/test utility. - Integration test — fixed to actually run.
The dual approach (endpoint-level changeStreamTokenRepository/changeStreamToken + route-level Resume Strategy via ResumeAware) is clean and well tested. This also addresses the earlier review from @orpiske requesting Resume Strategies API integration.
LGTM.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Description
Adds option to configure the change streams resume token in change streams consumer endpoint (property
resumeToken) and exposes the current resume token in exchange header (MongoDBConstants.RESUME_TOKEN).