This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new e1399e660 chore: mongodb-changes-stream-source can resume after a
restart with a token repository (#3280) (#3283)
e1399e660 is described below
commit e1399e660395df893feb1b96c856d50faa69ef81
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 21:04:58 2026 +0100
chore: mongodb-changes-stream-source can resume after a restart with a
token repository (#3280) (#3283)
The new optional tokenRepository option takes a reference to a
StateRepository
bean, passed to camel-mongodb as changeStreamTokenRepository. The resume
token
is stored after each change, so after a restart the Kamelet sends the
changes
made while it was stopped. Without the option nothing changes. No Camel
change
is needed: the repository stays a bean, as with the component.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
kamelets/mongodb-changes-stream-source.kamelet.yaml | 9 +++++++--
.../src/main/resources/META-INF/kamelets-index.json | 2 +-
.../kamelets/mongodb-changes-stream-source.kamelet.yaml | 9 +++++++--
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/kamelets/mongodb-changes-stream-source.kamelet.yaml
b/kamelets/mongodb-changes-stream-source.kamelet.yaml
index 3f781dc4b..1e1d5a938 100644
--- a/kamelets/mongodb-changes-stream-source.kamelet.yaml
+++ b/kamelets/mongodb-changes-stream-source.kamelet.yaml
@@ -38,7 +38,7 @@ spec:
Output: the body is JSON text. For an insert or a replace, it is the
whole new document. For an update, it is the whole document as it is when the
change is sent, read again from the collection, so it can already hold later
changes, and it is the text `null` when the document was deleted meanwhile;
`fullDocument` changes this. For a delete, it is an object with only the `_id`
of the deleted document. The `CamelMongoDbStreamOperationType` header says what
happened (`insert`, `update [...]
- Good to know: only changes made after the Kamelet starts are sent. It
does not save where it stopped, so the changes made while it is stopped, such
as during a restart, are never sent. The collection must exist when the Kamelet
starts; otherwise it fails to start with `Collection ... does not exist on the
database`. Reading the document again costs MongoDB one more read for each
update; set `fullDocument` to `default` to send `null` for an update instead.
MongoDB offers change stre [...]
+ Good to know: only changes made after the Kamelet starts are sent. It
does not save where it stopped, so the changes made while it is stopped, such
as during a restart, are never sent, unless `tokenRepository` is set: with a
`StateRepository` bean, such as an
`org.apache.camel.support.processor.state.FileStateRepository`, given as
`#name`, it stores the resume token after each change and, after a restart,
sends the changes made while it was stopped. The collection must exist when t
[...]
required:
- collection
- database
@@ -101,6 +101,11 @@ spec:
type: string
enum: ["updateLookup", "default", "whenAvailable", "required"]
default: updateLookup
+ tokenRepository:
+ title: Resume Token Repository
+ description: "A reference to a `StateRepository` bean that stores the
resume token after each change, such as `#changeStreamTokens`, so that after a
restart the Kamelet goes on from where it stopped. Declare the bean in the
integration, for example an
`org.apache.camel.support.processor.state.FileStateRepository` whose
`fileStore` property is set to
`#class:java.io.File('/data/change-stream-tokens.dat')`. Without it, the
changes made while the Kamelet is stopped are not sent."
+ type: string
+ example: "#changeStreamTokens"
dataTypes:
out:
headers:
@@ -135,7 +140,7 @@ spec:
properties:
mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&fullDocument={{?fullDocument}}&connectionUriString=RAW({{?connectionString}})"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&fullDocument={{?fullDocument}}&changeStreamTokenRepository={{?tokenRepository}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 084f11e21..296af537b 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1475,7 +1475,7 @@
"supportLevel" : "Stable",
"title" : "MongoDB Changes Stream Source",
"summary" : "Sends a message for each change to a collection of a MongoDB
database, such as a document inserted, updated or deleted, as it happens.",
- "description" : "Sends a message for each change to a collection of a
MongoDB database, such as a document inserted, updated or deleted, as it
happens.\n\nUse it to react to changes in MongoDB, for example to copy new
orders to another system or to keep a cache or a search index up to date. To
read the documents of a capped collection from the start, use `mongodb-source`.
To write documents, use `mongodb-sink`.\n\nOutput: the body is JSON text. For
an insert or a replace, it is the w [...]
+ "description" : "Sends a message for each change to a collection of a
MongoDB database, such as a document inserted, updated or deleted, as it
happens.\n\nUse it to react to changes in MongoDB, for example to copy new
orders to another system or to keep a cache or a search index up to date. To
read the documents of a capped collection from the start, use `mongodb-source`.
To write documents, use `mongodb-sink`.\n\nOutput: the body is JSON text. For
an insert or a replace, it is the w [...]
"group" : "MongoDB",
"namespace" : "Nosql",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
index 3f781dc4b..1e1d5a938 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
@@ -38,7 +38,7 @@ spec:
Output: the body is JSON text. For an insert or a replace, it is the
whole new document. For an update, it is the whole document as it is when the
change is sent, read again from the collection, so it can already hold later
changes, and it is the text `null` when the document was deleted meanwhile;
`fullDocument` changes this. For a delete, it is an object with only the `_id`
of the deleted document. The `CamelMongoDbStreamOperationType` header says what
happened (`insert`, `update [...]
- Good to know: only changes made after the Kamelet starts are sent. It
does not save where it stopped, so the changes made while it is stopped, such
as during a restart, are never sent. The collection must exist when the Kamelet
starts; otherwise it fails to start with `Collection ... does not exist on the
database`. Reading the document again costs MongoDB one more read for each
update; set `fullDocument` to `default` to send `null` for an update instead.
MongoDB offers change stre [...]
+ Good to know: only changes made after the Kamelet starts are sent. It
does not save where it stopped, so the changes made while it is stopped, such
as during a restart, are never sent, unless `tokenRepository` is set: with a
`StateRepository` bean, such as an
`org.apache.camel.support.processor.state.FileStateRepository`, given as
`#name`, it stores the resume token after each change and, after a restart,
sends the changes made while it was stopped. The collection must exist when t
[...]
required:
- collection
- database
@@ -101,6 +101,11 @@ spec:
type: string
enum: ["updateLookup", "default", "whenAvailable", "required"]
default: updateLookup
+ tokenRepository:
+ title: Resume Token Repository
+ description: "A reference to a `StateRepository` bean that stores the
resume token after each change, such as `#changeStreamTokens`, so that after a
restart the Kamelet goes on from where it stopped. Declare the bean in the
integration, for example an
`org.apache.camel.support.processor.state.FileStateRepository` whose
`fileStore` property is set to
`#class:java.io.File('/data/change-stream-tokens.dat')`. Without it, the
changes made while the Kamelet is stopped are not sent."
+ type: string
+ example: "#changeStreamTokens"
dataTypes:
out:
headers:
@@ -135,7 +140,7 @@ spec:
properties:
mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&fullDocument={{?fullDocument}}&connectionUriString=RAW({{?connectionString}})"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&fullDocument={{?fullDocument}}&changeStreamTokenRepository={{?tokenRepository}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}