Skip to content
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

Make ConcurrentKafkaListenerContainerFactoryConfigurer Generic #44638

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lipiridi
Copy link

@lipiridi lipiridi commented Mar 7, 2025

Summary

This PR updates ConcurrentKafkaListenerContainerFactoryConfigurer to be generic, allowing it to configure any container factory instead of being limited to <Object, Object>.

Motivation

  • Previously, the class was restricted to <Object, Object>, which prevented reuse for other container factories with different key/value types. Making it generic improves flexibility and reusability across various Kafka container configurations.
  • This change also enables configuring programmatically created container factories using Kafka listener properties from application.yml, providing greater control and consistency in Kafka consumer setup.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 7, 2025
…port configuring any container factory

Signed-off-by: Dimitrii Lipiridi <dimitrii.lipiridi@delasport.com>
@lipiridi lipiridi force-pushed the generic-kafka-container-configurer branch from 4ca1986 to 3e32cea Compare March 7, 2025 09:27
@wilkinsona wilkinsona changed the title Enhancement: Make ConcurrentKafkaListenerContainerFactoryConfigurer Generic Make ConcurrentKafkaListenerContainerFactoryConfigurer Generic Mar 7, 2025
@wilkinsona
Copy link
Member

When we're reviewing this we should keep in mind #40174 and #19221. Both issues are related to Kafka auto-configuration and generics.

@snicoll
Copy link
Member

snicoll commented Mar 7, 2025

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 ApplicationContext. I also wonder if the additional complexity is worth it given the primary goal of this class.

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 snicoll added the status: waiting-for-feedback We need additional information before we can continue label Mar 7, 2025
@lipiridi
Copy link
Author

lipiridi commented Mar 7, 2025

@snicoll thanks for your response!
We are currently creating container factories manually, but we want to configure them using spring.kafka.listener properties in a more convenient way, instead of writing boilerplate code.
Another risk is that the listener properties might be extended in the future, and we could miss these changes, failing to update the property injection code accordingly.

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;
    }
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 7, 2025
Signed-off-by: Dimitrii Lipiridi <dimitrii.lipiridi@delasport.com>
@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we'd like other members of the team to review status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants