springwolf-core icon indicating copy to clipboard operation
springwolf-core copied to clipboard

feat: Extract generic type for KafkaListeners in batch mode

Open timonback opened this issue 3 years ago • 0 comments

The KafkaPayloadTypeExtractor contains the logic to extract the payload type, which previously was part of ClassLevelKafkaListenerScanner and MethodLevelKafkaListenerScanner.

If the parameter is of type List<?>, reflection is used to extract the underlying type. This solution assumes by using the List type, Kafka batch mode is used.

A future improvement can be to only extract the generic when the KafkaListener annotation is used together with the batch property. A library update for spring-kafka is possible: https://docs.spring.io/spring-kafka/api/org/springframework/kafka/annotation/KafkaListener.html#batch()

To demo it, one listener in ExampleConsumer is updated to use batch mode.

Relates to https://github.com/springwolf/springwolf-core/issues/87

timonback avatar Sep 08 '22 17:09 timonback