-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-23336: camel-mongodb - Expose Resume Token (Change Streams Consumer) #22674
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
Merged
davsclaus
merged 5 commits into
apache:main
from
Michwo:feat-camel-mongodb-cs-resume-token
Jun 24, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
df357ee
Implement resume strategy support for camel-mongodb
Michwo 84c983f
Merge branch 'feat-camel-mongodb-cs-resume-token' of https://github.c…
Michwo 94c01be
Fix Integration test MongoDbChangeStreamsResumeIT not running
Michwo c0f7353
Move repository stop after thread stop
Michwo 85ab88a
Extract duplicate InMemoryStringResumeCache to a support class
Michwo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 49 additions & 47 deletions
96
...og/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mongodb.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 49 additions & 47 deletions
96
...-mongodb/src/generated/resources/META-INF/org/apache/camel/component/mongodb/mongodb.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...ongodb/src/generated/resources/META-INF/services/org/apache/camel/mongodb-adapter-factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Generated by camel build tools - do NOT edit this file! | ||
| class=org.apache.camel.component.mongodb.MongoDbResumeAdapter |
2 changes: 2 additions & 0 deletions
2
...ongodb/src/generated/resources/META-INF/services/org/apache/camel/mongodb-resume-strategy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Generated by camel build tools - do NOT edit this file! | ||
| class=org.apache.camel.processor.resume.mongodb.MongoDbResumeStrategy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...l-mongodb/src/main/java/org/apache/camel/component/mongodb/ChangeStreamCommitManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.mongodb; | ||
|
|
||
| import org.apache.camel.spi.StateRepository; | ||
| import org.apache.camel.util.ObjectHelper; | ||
| import org.bson.BsonDocument; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class ChangeStreamCommitManager implements CommitManager { | ||
| private static final Logger LOG = LoggerFactory.getLogger(ChangeStreamCommitManager.class); | ||
|
|
||
| private final StateRepository<String, String> resumeTokenRepository; | ||
| private final String resumeTokenKey; | ||
| private final String explicitResumeToken; | ||
|
|
||
| private BsonDocument cachedResumeToken; | ||
|
|
||
| public ChangeStreamCommitManager(MongoDbChangeStreamsConsumer consumer, MongoDbEndpoint endpoint) { | ||
| this.resumeTokenRepository = endpoint.getChangeStreamTokenRepository(); | ||
| this.explicitResumeToken = endpoint.getChangeStreamToken(); | ||
|
|
||
| String routeId = consumer.getRouteId(); | ||
| if (ObjectHelper.isEmpty(routeId)) { | ||
| routeId = endpoint.getEndpointUri(); | ||
| } | ||
|
|
||
| this.resumeTokenKey = serializeResumeTokenKey(routeId, endpoint.getCollection()); | ||
| } | ||
|
|
||
| @Override | ||
| public BsonDocument readResumeToken() { | ||
| if (ObjectHelper.isNotEmpty(explicitResumeToken)) { | ||
| return BsonDocument.parse(explicitResumeToken); | ||
| } | ||
|
|
||
| if (resumeTokenRepository == null) { | ||
| return null; | ||
| } | ||
|
|
||
| String serialized = resumeTokenRepository.getState(resumeTokenKey); | ||
| if (ObjectHelper.isEmpty(serialized)) { | ||
| return null; | ||
| } | ||
|
|
||
| return BsonDocument.parse(serialized); | ||
| } | ||
|
|
||
| @Override | ||
| public void recordResumeToken(BsonDocument resumeToken) { | ||
| this.cachedResumeToken = resumeToken; | ||
| } | ||
|
|
||
| @Override | ||
| public void commit() throws Exception { | ||
| if (cachedResumeToken == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (resumeTokenRepository != null) { | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Saving resume token repository state for key {}", resumeTokenKey); | ||
| } | ||
| resumeTokenRepository.setState(resumeTokenKey, cachedResumeToken.toJson()); | ||
| } | ||
| } | ||
|
|
||
| private static String serializeResumeTokenKey(String routeId, String collection) { | ||
| return routeId + '/' + collection; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/CommitManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.mongodb; | ||
|
|
||
| import org.bson.BsonDocument; | ||
|
|
||
| public interface CommitManager { | ||
|
|
||
| BsonDocument readResumeToken(); | ||
|
|
||
| void recordResumeToken(BsonDocument resumeToken); | ||
|
|
||
| void commit() throws Exception; | ||
| } |
31 changes: 31 additions & 0 deletions
31
...onents/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/CommitManagers.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.mongodb; | ||
|
|
||
| public final class CommitManagers { | ||
|
|
||
| private CommitManagers() { | ||
| } | ||
|
|
||
| public static CommitManager createCommitManager(MongoDbChangeStreamsConsumer consumer, MongoDbEndpoint endpoint) { | ||
| if (endpoint.getChangeStreamTokenRepository() == null && consumer.getResumeStrategy() == null) { | ||
| return new NoopCommitManager(endpoint); | ||
| } | ||
|
|
||
| return new ChangeStreamCommitManager(consumer, endpoint); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.