allthingssecurity opened a new pull request, #27985: URL: https://github.com/apache/camel/pull/27985
# Description [CAMEL-25700](https://issues.apache.org/jira/browse/CAMEL-25700) With `extendMessageVisibility=true` the SQS consumer keeps the messages it processes invisible: the `TimeoutExtender` task calls `ChangeMessageVisibilityBatch` for every message it knows before the visibility timeout runs out. A poll receives up to `maxMessagesPerPoll` messages at once, and the visibility timeout of all of them starts at that receive. `processBatch` registered a message with the extender only when its own turn came (`timeoutExtender.add(exchange)` inside the processing loop). With a synchronous route, the messages that waited behind slower ones were not extended at all; once the earlier messages had taken longer than `visibilityTimeout`, SQS made the waiting messages visible again and delivered them a second time. This is the scenario of CAMEL-10587 (2016, `maxMessagesPerPoll=10`, "after 30 seconds only 1 message is in flight"), which was closed as Abandoned after a commit that only changed the start order; the per-message registration stayed in the loop. Changes (`Sqs2Consumer` only): - `processBatch` registers every message of the batch with the extender before it routes the first one. - The messages that are not routed (the consumer is stopping or suspending, or the processor threw) are removed from the extender afterwards, so that they become visible again as they did before. `TimeoutExtender` gets a small `remove(Exchange)` method for this, also used by its own completion callback. - The extender's rule is unchanged: an entry is extended only when its deadline is near, so a message that is processed quickly is still not extended. What users can notice: with `extendMessageVisibility=true` and `maxMessagesPerPoll` > 1, the messages that wait in the batch stay invisible and are no longer delivered twice; they are extended while they wait (one `ChangeMessageVisibilityBatch` entry per message and visibility period, up to 10 per request, as for the message being processed). Nothing changes with the default of one message per poll or without `extendMessageVisibility`. No option or default changes, so no upgrade guide entry. Tests: - New `SqsConsumerExtendMessageVisibilityBatchTest` (2 tests) with the module's `AmazonSQSClientMock`, no AWS, every wait bounded, no sleeps: - two messages in one poll (`maxMessagesPerPoll=2&visibilityTimeout=2&extendMessageVisibility=true`); the route holds the first message until the extender has sent an entry for the receipt handle of the second (at most 10 seconds). Fails on main: `Expecting value to be true but was false` (the second message is never extended while the first is processed); - the route is suspended while the first message is processed, so the second one is not routed; it must not be extended afterwards. This one passes on main too (the message is never registered there); it guards the removal of unrouted messages that the change adds. - With the change the camel-aws2-sqs unit tests pass: 77 run, 0 failures, 0 skipped. What is not changed: - A processor that throws (rather than failing the exchange) still leaves its own message registered until the consumer stops, as before. - Messages of a batch that are skipped because the consumer stops are not released back to SQS explicitly; they become visible after the visibility timeout, as before. What was not run: the module's integration tests (they need LocalStack), a real SQS queue. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-25700](https://issues.apache.org/jira/browse/CAMEL-25700). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested camel-aws2-sqs, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
