oscerd opened a new pull request, #26961:
URL: https://github.com/apache/camel/pull/26961
Two defects in the MongoDB consumers, a commit each, plus the upgrade-guide
entries.
## CAMEL-25024 — a failed exchange was discarded without a trace
`MongoDbChangeStreamsThread`:
```java
consumer.getProcessor().process(exchange);
...
} catch (Exception ignored) {
}
```
`MongoDbTailingThread`:
```java
try {
consumer.getProcessor().process(exchange);
} catch (Exception e) {
// do nothing
}
tailTracking.setLastVal(dbObj); // outside the try
```
Neither called `getExceptionHandler()`, so a route failure produced **no log
output at all** and
`bridgeErrorHandler` had no effect on either consumer. The empty catch is
older than the visible history —
it is already present in the 2019 commit that renamed `camel-mongodb3` to
`camel-mongodb`, and no issue
has touched it since.
The tailable consumer additionally recorded a failed record as consumed,
because `setLastVal` ran whether
or not the exchange succeeded; with `persistentTailTracking=true` that
skipped it across restarts too. It
now runs only on the success path.
**What this PR deliberately does not change:** the change-streams consumer
still advances its resume
token past a failed event. It cannot be fixed in the catch block — the
failed event's token is not
committed, but the *next* event that succeeds commits its own, so the
position moves regardless.
Preventing that means the consumer has to stop committing or reprocess,
which is a redesign rather than a
bug fix. Happy to open a follow-up if you want that behaviour.
## CAMEL-25025 — a non-ObjectId `_id` looped the consumer forever
```java
ObjectId documentId =
dbObj.getDocumentKey().getObjectId(MONGO_ID).getValue();
```
Checked against `bson-5.9.2` / `mongodb-driver-core-5.9.2`:
* `BsonDocument.getObjectId(key)` is `throwIfKeyAbsent(key);
get(key).asObjectId();`, so it throws
`BsonInvalidOperationException` when `_id` is a string, a number or a
compound key — all ordinary in
MongoDB.
* `ChangeStreamDocument.getDocumentKey()` is `@Nullable`, so `invalidate`,
`drop`, `rename` and
`dropDatabase` events hit an NPE on the same line.
* `BsonInvalidOperationException extends BSONException`, a **sibling** of
`MongoException`, so the
`catch (MongoException e)` in `doRun()` never applied.
Either exception reached the hardening added by **CAMEL-16025**, which keeps
the thread alive and
regenerates the cursor. But the failure happens *before* the exchange is
created, so the resume token
never advanced and the regenerated cursor returned the same event: the
consumer failed on it once per
`cursorRegenerationDelay` (default 1 s) for as long as the route ran.
CAMEL-16025 fixed the thread death
— this is the half that remained, and the issue is linked to it.
The key is now read defensively and the id keeps its natural Java type, with
anything that is not an
`ObjectId` decoded the way the driver decodes a document. The header is
absent rather than fatal for
events with no document key, and its declared `javaType` moves from
`org.bson.types.ObjectId` to `Object`
to match, which is what regenerates the catalog and the endpoint DSL here.
The stack trace also moves to the "will try again" branch of the consumer
thread — that is the branch
that repeats, so it is the one worth diagnosing.
## Tests
`MongoDbChangeStreamsThreadTest` covers the document key directly: generated
`ObjectId`, string id,
numeric id, compound id, an event with no document key, and a key with no
`_id`. Reverting to the blind
`getObjectId` read fails **5 of the 6** with exactly `Value expected to be
of type OBJECT_ID is of
unexpected type DOCUMENT`, `Document does not contain key _id` and the NPE;
only the generated-ObjectId
case still passes, which is the one that always worked.
Module unit suite green (15 tests), full reactor `mvn clean install
-DskipTests -DskipITs` green.
## One unrelated line
The guide commit also restores the blank line before the `===
camel-debezium` heading further up the
file. That heading arrived with CAMEL-24889 and the `camel-crypto` entry
landed against it, leaving no
blank line, so AsciiDoc renders the title as body text — it is live on
`main` today. It is a one-line
repair of my own earlier merge, in the file this commit already edits; say
the word if you would rather
it went separately.
_Claude Code on behalf of oscerd_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]