allthingssecurity opened a new pull request, #27677:
URL: https://github.com/apache/camel/pull/27677

   # Description
   
   [CAMEL-25527](https://issues.apache.org/jira/browse/CAMEL-25527)
   
   `MyBatisConsumer.processBatch` ran the `onConsume` statements after every 
exchange, also when the exchange failed (a failed route leaves the exception on 
the exchange instead of throwing it) or was marked rollback only. The row was 
then marked as consumed (in the documented example `update ACCOUNT set 
PROCESSED = true`) and was not polled again, although the javadoc says the 
statements run "after successful processing". `SqlConsumer.processBatch` picked 
`onConsumeFailed` from `exchange.isFailed()` only, so a rollback only exchange 
(no exception) got `onConsume`. This is the sibling of the camel-jooq fix 
CAMEL-25511.
   
   Now:
   - camel-mybatis runs `onConsume` only when the exchange is neither failed 
nor rollback only. The row of a failed exchange is consumed again by the next 
poll, so a row that always fails is processed at every poll; 
`onException(...).handled(true)` consumes it anyway (docs and catalog copy say 
so).
   - camel-sql runs `onConsumeFailed` for a rollback only exchange, and no 
statement when `onConsumeFailed` is not set (as for a failed exchange), so the 
row is consumed again by the next poll.
   - With `transacted=true`, both consumers now break out of the batch at a 
rollback only exchange, as they do at a failed one. That code path created 
`RollbackExchangeException` with a `null` exchange, which throws a 
`NullPointerException` (it had never run, since `isFailed()` implies an 
exception); it is now created with the exchange, before the exchange is 
released.
   
   Both consumers already create their exchanges with `createExchange(false)` 
and call `releaseExchange(exchange, false)` after reading the outcome, so the 
change also holds with the pooled exchange factory; the tests run with it too. 
No extra per-message cost (one more flag read). An upgrade guide note is added 
for 4.23 under its own heading next to the existing camel-mybatis entry.
   
   Tests:
   - New `MyBatisOnConsumeFailedTest`: one poll (scheduler not started) where 
the route fails for one account, marks one exchange rollback only, or (with 
`transacted=true`) marks the second of three rollback only.
   - New `SqlConsumerRollbackOnlyTest`: one poll over the three projects of 
`createAndPopulateDatabase.sql` where the AMQ exchange is marked rollback only: 
with `onConsumeFailed`, without it, and with `transacted=true`.
   - `MyBatisOnConsumeFailedPooledExchangeTest` and 
`SqlConsumerRollbackOnlyPooledExchangeTest` run the same tests with 
`PooledExchangeFactory`.
   - Without the change all 12 fail, e.g. `expected: <[2]> but was: <[]>`, 
`expected: <[DONE, BAD, DONE]> but was: <[DONE, DONE, DONE]>`, `expected: 
<[DONE, ASF, DONE]> but was: <[DONE, DONE, DONE]>` and `Expected 
org.apache.camel.RollbackExchangeException to be thrown, but nothing was 
thrown.`
   - With the change: camel-mybatis 52 tests, camel-sql 323 tests (3 skipped), 
0 failures. `SqlFunctionDataSourceTest` was excluded locally: it needs 
MariaDB4j, which does not install on my machine, and fails the same way without 
the change.
   
   Not changed here: `JpaConsumer` runs the `@Consumed` delete handler when 
`exchange.getException() == null`, so a rollback only exchange is consumed 
there as well; that can be a follow-up if wanted.
   
   # 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).
   
   # 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-mybatis and camel-sql with `install`, 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]

Reply via email to