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

   ## What this does
   
   Three small, **behaviour-preserving** performance clean-ups that remove 
per-message allocations on the camel-kafka hot paths. No public API or option 
changes.
   
   ### 1. Producer — redundant callback allocation on the single-message async 
path
   `KafkaProducer.process(Exchange, AsyncCallback)` sent a single record via 
`doSend(exchange, record, cb)`. Because the key was non-null, `doSend` 
allocated a `KafkaProducerMetadataCallBack` **and** a `DelegatingCallback` for 
every message — even though the parent `KafkaProducerCallBack` already records 
the metadata and any exception on the same exchange. The single-message path 
now passes a `null` key, so it sends with the parent callback alone (two fewer 
short-lived allocations per message). The resulting `CamelKafkaRecordMeta` 
header is unchanged (a one-element `List<RecordMetadata>`). The iterator/batch 
path is untouched — it genuinely needs a per-element metadata callback.
   
   ### 2. Consumer — per-record `Stream`/lambda allocations in header 
propagation
   `KafkaRecordProcessor.propagateHeaders` built a `Stream` + spliterator + two 
capturing lambdas for **every** consumed record and re-resolved 
`exchange.getIn()` per header. It now iterates `consumerRecord.headers()` with 
a plain loop and a hoisted `Message`. Behaviour is identical.
   
   ### 3. Transforms — `ObjectMapper` constructed per message
   Six JSON transform beans (`HoistField`, `MaskField`, `ExtractField`, 
`ReplaceField`, `MessageTimestampRouter`, `ValueToKey`) built a `new 
ObjectMapper()` on every invocation. `ObjectMapper` is expensive to construct 
and thread-safe once configured; these back the corresponding Kamelet actions 
and run per message. They now reuse a single shared static `ObjectMapper`.
   
   ## Tests
   
   These are behaviour-preserving optimizations covered by existing tests, all 
green in a full `camel-kafka` module build (unit + integration):
   - `KafkaProducerTest` (23 tests) — including `processAsyncSendsMessage`, 
which exercises the single-message async path and asserts the 
`CamelKafkaRecordMeta` header.
   - The transform unit tests (`HoistFieldTest`, `MaskFieldTest`, 
`MessageTimestampRouterTest`, `ReplaceFieldTest`, …).
   - The consumer integration tests (`KafkaConsumerFullIT`, …) which cover 
header propagation.
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-24779
   
   _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]

Reply via email to