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

Provide a way to define a ContainerCustomizer per KafkaListener #2825

Closed
frosiere opened this issue Oct 3, 2023 · 6 comments
Closed

Provide a way to define a ContainerCustomizer per KafkaListener #2825

frosiere opened this issue Oct 3, 2023 · 6 comments

Comments

@frosiere
Copy link
Contributor

frosiere commented Oct 3, 2023

Following https://stackoverflow.com/questions/77193702/consumerrebalancelistener-and-or-containerproperties-override-per-container,

Through a new property on the KafkaListener annotation, it should be possible to specify the bean name of the ContainerCustomizer associated to the listener.

@KafkaListener(... containerCustomizer="myContainerCustomizerBeanName" ...)
void on(ConsumerRecords records) {
...

If provided, this customizer would override the default factory customizer.

See KafkaListenerAnnotationBeanPostProcessor and KafkaListenerEndpoint for internal details.

Would be great to have this feature on both Spring Kafka 2.9.x and 3.0.x

@garyrussell
Copy link
Contributor

It is unlikely this would be back ported to versions earlier than the upcoming 3.1.

It's really just a convenience feature; the existing single customizer per factory has access to the container's listener id when performing customization.

@garyrussell
Copy link
Contributor

Actually, this is not so straightforward; defining multiple beans will disable Boot's capability of auto configuring the default customizer. And, if you only define one bean, it will be detected by Boot and auto configure it into the factory.

We will probably have to use a different interface for this customizer.

@frosiere
Copy link
Contributor Author

frosiere commented Oct 4, 2023

Good catch. Didn't see it on the 2.9.x as this configuration has been introduced on the 3.1.x (spring-projects/spring-boot#34033). Seems weird to not have used the ConcurrentKafkaListenerContainerFactoryConfigurer to set the customizer on the factory.

This may be confusing to introduce a new interface, but this seems the way to go...

@frosiere
Copy link
Contributor Author

frosiere commented Oct 9, 2023

What about ContainerConfigurer? May it help if I drop a PR for that or do you prefer to implement it yourself?

@garyrussell
Copy link
Contributor

The Boot team does not like us using *Configurer - that is their convention and it causes some confusion; it is unlikely that they will add one for this, but in the past we ended up with the same class name in Boot and the upstream project.

Happy to receive a PR, if we can come up with a name.

Maybe ContainerPostProcessor for the interface? (the attribute name can still be customizer; perhaps should be because we want this to be applied instead of the common customizer - and the Javadocs should explain that).

@frosiere
Copy link
Contributor Author

Looks good to me. Will drop a PR this week. Thanks.

@garyrussell garyrussell modified the milestones: 3.1.0-RC1, 3.1 Backlog Oct 16, 2023
frosiere added a commit to frosiere/spring-kafka that referenced this issue Oct 16, 2023
frosiere added a commit to frosiere/spring-kafka that referenced this issue Oct 16, 2023
frosiere added a commit to frosiere/spring-kafka that referenced this issue Oct 18, 2023
@garyrussell garyrussell modified the milestones: 3.1 Backlog, 3.1.0 Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants