davsclaus opened a new pull request, #30746: URL: https://github.com/apache/camel/pull/30746
_Claude Code on behalf of davsclaus_ JIRA: https://issues.apache.org/jira/browse/CAMEL-27180 ## What was wrong The polling `aws2-kinesis` consumer without `shardId` reads all the shards of the stream. After a split or a merge, the closed parent shard stays in the `ListShards` result for the retention period of the stream (24 hours by default), and since CAMEL-25569 the consumer goes on with the child shards. With `shardClosed=fail`, once the parent shard was read to its end, `handleClosedShard` threw an `IllegalStateException(ReachedClosedStatusException)` inside the `parallelStream().forEach(...)` of `poll()` on every later poll. The child shards were still read by the other tasks, so the consumer did not stop; it logged a WARN with a stack trace on every poll. Because `forEach` returns on the first exception, the next poll could start while the shard tasks of the failed poll were still reading and routing, the routed record count of the poll was lost, and `forceConsumerAsReady()` was skipped. The `shardClosed` option description said that with `ignore` and `silent` the consumer processes no new messages until restarted (only true with `shardId`), and named `ReachedClosedStateException` instead of `ReachedClosedStatusException`. ## What changed - `shardClosed=fail` hands a `ReachedClosedStatusException` to the consumer's `ExceptionHandler` once per closed shard (logged as a WARN by default, routed to the error handler with `bridgeErrorHandler=true`), and then skips the shard like `silent`. The reported shards are remembered per consumer and cleared in `doStop`. The poll does not fail. - With `shardId` set, the shard is reported once, after which the consumer has nothing more to read (before, every poll failed). - Each shard task of the parallel stream catches its own failure. A failed shard (other than closed) still fails the poll, as before, but only after all shard tasks finished; the poll throws the exception of the shard itself (no longer wrapped by the parallel stream), with the failures of other shards added as suppressed. I kept the poll failing, rather than handing each shard failure to the exception handler, so the consumer health check, `backoffErrorThreshold` and the poll strategy still see failing reads, the same as with `shardId` set. No new executor (CAMEL-26670 is separate). - `ReachedClosedStatusException` now has a message (shard and stream). - The `shardClosed` description names the right exception and describes `ignore`, `silent` and `fail` with and without `shardId`. Regenerated the component JSON, the catalog copy, the endpoint DSL and the component DSL. - Upgrade guide 4.24 entry: `shardClosed=fail` reports once and skips instead of failing every poll; how to react with `bridgeErrorHandler`; a failed shard fails the poll after the other shards are read. - The javadoc of the DST `KinesisWorld` said that `fail` ends the consumption of the stream by design; updated. The world still picks `ignore` or `silent` only, so existing seeds keep their configuration. ## Behaviour change The existing `KinesisConsumerClosedShardWithFailTest` asserted that the poll after the shard closed throws `IllegalStateException`. That is the behaviour this PR changes, so the test now asserts that the poll does not fail and the exception handler gets one `ReachedClosedStatusException`. It also no longer starts the scheduler, so only the test polls. ## Tests - `KinesisConsumerClosedShardWithFailTest` (4 tests, single shard): the closed shard is reported once over several polls and read once, with and without `shardId`, and reported again after the consumer is stopped and started. - New `KinesisConsumerClosedShardWithFailMultiShardTest` (2 tests): a closed parent with two child shards; the parent is reported exactly once, the later polls return the child records (4, then 2, 2, 2) and do not fail. A second test makes the read of one child fail: the poll throws that exception only after the other child has been routed, the closed parent is reported, and the next poll reads both children again. - Both new test classes fail against the old consumer (6 of 6 tests). - `mvn -o test` in `camel-aws2-kinesis`: 1079 tests, 0 failures, including the 1000 seeds of `KinesisConsumerDstTest`, and the `ignore`/`silent` tests unchanged. 🤖 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]
