oscerd opened a new pull request, #26523: URL: https://github.com/apache/camel/pull/26523
## What this does Fixes two related robustness problems in the **transactional producer** async path. ### 1. Transaction begin (and body resolution) ran outside the `try` `KafkaProducer.process(Exchange, AsyncCallback)` resolved `message.getBody()` and called `startKafkaTransaction(exchange)` **before** the `try` that guards sending. If `kafkaProducer.beginTransaction()` threw (or a lazy body conversion threw), the exception escaped `process()` **without calling `callback.done(...)`**, violating the async producer contract (the caller's callback is never completed). **Fix:** the body resolution and `startKafkaTransaction` call are now inside the `try`, so a failure is handled like any other send failure — the exception is set on the exchange and the async callback is completed. ### 2. UnitOfWork marked transacted before the transaction actually began In `startKafkaTransaction` the order was `uow.beginTransactedBy(id)` → `kafkaProducer.beginTransaction()` → `uow.addSynchronization(...)`. If `beginTransaction()` threw, the UoW was already flagged as transacted by this id but **no synchronization was registered**, so nothing would ever commit/abort it and the flag dangled for the rest of the exchange. **Fix:** call `kafkaProducer.beginTransaction()` first, and only then mark the UoW and register the synchronization, so a begin failure leaves the UoW untouched. Both changes are limited to the transactional async path; non-transactional sends are unaffected. ## Tests - `KafkaProducerTest#processAsyncCompletesCallbackWhenBeginTransactionFails` — makes `beginTransaction()` throw and asserts that `process()` sets the exception and completes the async callback (instead of throwing), and that the UnitOfWork is **not** marked transacted and no synchronization is registered. This test fails on the previous code (the exception escaped `process()` and the UoW was already flagged). Full `camel-kafka` module build (unit + integration tests) is green. JIRA: https://issues.apache.org/jira/browse/CAMEL-24780 _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]
