-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Extract generic type for KafkaListeners in batch mode #89
feat: Extract generic type for KafkaListeners in batch mode #89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, it's good to see so much code re-used. Please see my comments, I really think we can use this extractor for the amqp plugin as well
...va/io/github/stavshamir/springwolf/asyncapi/scanners/channels/KafkaPayloadTypeExtractor.java
Outdated
Show resolved
Hide resolved
...va/io/github/stavshamir/springwolf/asyncapi/scanners/channels/KafkaPayloadTypeExtractor.java
Outdated
Show resolved
Hide resolved
...github/stavshamir/springwolf/asyncapi/scanners/channels/MethodLevelKafkaListenerScanner.java
Show resolved
Hide resolved
...va/io/github/stavshamir/springwolf/asyncapi/scanners/channels/KafkaPayloadTypeExtractor.java
Outdated
Show resolved
Hide resolved
5289884
to
60db5a6
Compare
I updated the PR with a larger refactoring and moving duplicated code to Abstract classes in core. The amqp and kafka listeners are slimmer now, although there is still some complexity through the abstract methods. Since the release is around the corner, I think this is a feature for the following release. Regarding the batch mode, yes, this by default assumes that all List Payloads are batch methods. In the future this could be made configurable (batch-mode: yes/no), but at this point I would assume that people define their own payload types and not use List in non-batch mode (defining |
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. To demo it, one listener in ExampleConsumer is updated to use batch mode.
Fixes nondeterministic (HashMap) ordering when channels for the same topic are merged
f63bbe0
to
cfe5942
Compare
I really like this refactoring, it will make it much much easier to implement more plugins based on listener annotations. Great job! |
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 #87