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

Add spring.kafka.enabled configuration to disable KafkaAutoConfiguration #41687

Open
DanielLiu1123 opened this issue Aug 2, 2024 · 7 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@DanielLiu1123
Copy link
Contributor

DanielLiu1123 commented Aug 2, 2024

Background

In our use case, we need to support connecting to multiple Kafka servers. Spring does not support this. We want to use Spring's KafkaTemplate, but when spring-kafka and spring boot are both on the classpath, KafkaAutoConfiguration is automatically activated, and there is no configuration like spring.kafka.enabled to disable the auto-configuration.

Why not use @SpringBootApplication(exclude = KafkaAutoConfiguration.class) to exclude the auto-configuration class?

Changing code for every service just sucks... We will provide a library to support configuring multiple Kafka servers, like creating our own Spring Boot starter.

More thoughts

Consider providing a spring.<module>.enabled configuration for Spring Boot modules (e.g., spring.datasource.enabled, spring.redis.enabled). When users develop based on Spring Boot, if there is this configuration, they do not need to force auto-configuration because sometimes users just want to use Spring's code (JdbcTemplate, RedisTemplate), not auto-configuration. I have written some Spring Boot starters, and I always provide an enabled configuration for a feature (with a reasonable default value). It works very well and makes testing easier.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 2, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Aug 2, 2024

Btw, you can also exclude auto-configurations via properties. That way you can set it via the environment and don't have to change code.

Does that solve your problem?

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Aug 2, 2024
@quaff
Copy link
Contributor

quaff commented Aug 5, 2024

Btw, you can also exclude auto-configurations via properties. That way you can set it via the environment and don't have to change code.

Does that solve your problem?

See #38641.

@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 Aug 5, 2024
@quaff
Copy link
Contributor

quaff commented Aug 5, 2024

I'd prefer #41669, is it suitable for your use case? @DanielLiu1123

@DanielLiu1123
Copy link
Contributor Author

Btw, you can also exclude auto-configurations via properties.

I did miss that configuration, but I think manually excluding auto-configuration is not suitable.

To support connecting to multiple Kafka servers, I need to disable Kafka auto-configuration in the library. However, some services use KafkaTemplate provided by Kafka auto-configuration, so Kafka auto-configuration needs to be enabled in some services. Manually excluding auto-configuration in the library and then enabling it in the app configuration is very strange. But if there is an enabled configuration, I only need to set spring.kafka.enabled=false in the library, and for those services that rely on auto-configuration, just set spring.kafka.enabled=true.

That way you can set it via the environment and don't have to change code.

In our team, we avoid using environment variables or system properties to override configurations. We only inject sensitive data using environment variables. We want all configurations to be explicitly declared.

@DanielLiu1123
Copy link
Contributor Author

I'd prefer #41669, is it suitable for your use case?

I still don’t think manually excluding auto-configuration is a good way. For users, providing an enabled configuration for a feature/functionality is simpler and clearer.

@quaff
Copy link
Contributor

quaff commented Aug 5, 2024

I'd prefer #41669, is it suitable for your use case?

I still don’t think manually excluding auto-configuration is a good way. For users, providing an enabled configuration for a feature/functionality is simpler and clearer.

spring.kafka.enabled is opposite to spring.autoconfigure.exclusion.org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,
the advantage of spring.*.enabled is more shorter and readable, but the disadvantage is obvious, Spring Boot need add the configuration key for every AutoConfiguration which is cumbersome and error-prone.
I'd prefer spring.autoconfigure.exclusion.* and alias spring.autoconfigure.exclusion.org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration=${spring.kafka.disabled:false}.

@mhalbritter mhalbritter added the for: team-meeting An issue we'd like to discuss as a team to make progress label Aug 5, 2024
@mhalbritter
Copy link
Contributor

I'm flagging this so that we can discuss it in our next team meeting. The enabled properties for auto-config come up here and there.

@philwebb philwebb changed the title Add spring.kafka.enabled configuration to disable KafkaAutoConfiguration Add spring.kafka.enabled configuration to disable KafkaAutoConfiguration Aug 12, 2024
@wilkinsona wilkinsona removed the for: team-meeting An issue we'd like to discuss as a team to make progress label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

5 participants