-
Notifications
You must be signed in to change notification settings - Fork 41.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make ConcurrentKafkaListenerContainerFactoryConfigurer Generic #44638
Make ConcurrentKafkaListenerContainerFactoryConfigurer Generic #44638
Conversation
…port configuring any container factory Signed-off-by: Dimitrii Lipiridi <dimitrii.lipiridi@delasport.com>
4ca1986
to
3e32cea
Compare
Unfortunately, I am not sure that we should be making this change. The configurer is mostly for applying auto-configuration to custom container that are to be exposed for management of the This PR doesn't introduce any tests and isn't actionable as such. Before you amend that, I'd like to better understand what you actually mean in the two motivations. Can you provide examples of both and show how the current class is relevant? |
@snicoll thanks for your response! Here is the a real example of usage I'm trying to achieve: @Configuration
@RequiredArgsConstructor
public class KafkaConfiguration {
private final KafkaProperties kafkaProperties;
@Bean
public ConcurrentKafkaListenerContainerFactory<String, GenericRecord> buildFactory() {
var buildProperties = this.kafkaProperties.buildConsumerProperties(null);
DefaultKafkaConsumerFactory<String, Object> consumerFactory =
new DefaultKafkaConsumerFactory<>(buildProperties, new StringDeserializer(), new ErrorHandlingDeserializer<>(new KafkaAvroDeserializer()));
ConcurrentKafkaListenerContainerFactory<String, GenericRecord> factory =
new ConcurrentKafkaListenerContainerFactory<>();
ConcurrentKafkaListenerContainerFactoryConfigurer<String, GenericRecord> configurer = new ConcurrentKafkaListenerContainerFactoryConfigurer<>();
configurer.setKafkaProperties(this.kafkaProperties);
configurer.configure(factory, consumerFactory);
return factory;
}
} |
Signed-off-by: Dimitrii Lipiridi <dimitrii.lipiridi@delasport.com>
@lipiridi we won't make the setters public, for sure as this is meant to be injected in user's code and they can't mutate what's been configured for them. Rather, they should apply the configurer and adapt whatever code is necessary. I had a look to your sample, and we'll take it to the team. This part of the API always was a bit strange to me, perhaps @artembilan has an opinion about this change? |
I think this is wrong:
There is no need in creating this object manually, rather do this:
I agree with @snicoll , that those generics for key/value on all the Apache Kafka API is painful and useless. Tell us, please, why current |
@artembilan Hello! |
Hm. OK. My bad. |
@artembilan the question is how is it supposed to cast the typified I'm okay with not making all methods public, especially since I customize the configurer only by setting my own error handler, and the |
It's unfortunate that the Kafka API is done this way, but I don't think this is the right place to fix the problem. Introducing the generics would complicate the code for no good reason. The current situation is far from ideal but I'd rather open this against the Kafka project. |
as a workaround, you can use the following: @SuppressWarnings({ "unchecked", "rawtypes" })
private ConcurrentKafkaListenerContainerFactory<Object, Object> buildFactory(
ConcurrentKafkaListenerContainerFactoryConfigurer configurer) {
Map<String, Object> kafkaProperties = this.properties.buildConsumerProperties();
ErrorHandlingDeserializer<Object> avroDeserializer = new ErrorHandlingDeserializer<>(
new KafkaAvroDeserializer());
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
configurer.configure(factory,
new DefaultKafkaConsumerFactory(kafkaProperties, new StringDeserializer(), avroDeserializer));
return factory;
}
|
You can do just like this instead:
That
I understand your pain and really don't see reason in those generics on the Perhaps with the current |
Summary
This PR updates ConcurrentKafkaListenerContainerFactoryConfigurer to be generic, allowing it to configure any container factory instead of being limited to <Object, Object>.
Motivation