CAMEL-22760: Bridge spring.kafka.* properties to camel-kafka component#1709
Conversation
When using camel-kafka-starter with Spring Boot, users previously had to duplicate their Kafka configuration under both spring.kafka.* and camel.component.kafka.* properties. This adds a SpringKafkaPropertiesAutoConfiguration that automatically bridges Spring Boot's KafkaProperties to the Camel Kafka component configuration, including: - bootstrap-servers -> brokers - security.protocol -> security-protocol - ssl.* properties (keystore, truststore, types, passwords) - consumer.group-id -> group-id - client-id - SASL properties from spring.kafka.properties map Explicit camel.component.kafka.* settings always take precedence. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
this is a good idea, a JIRA would be good so we have it there also. And add a note in the 4.19 migration guide especially if this would default happen so end users would be aware when upgrading |
|
I guess if not already exists should be an easy option to set = true or = false to turn this bridge on|off |
- Use @autoConfiguration(after/before) instead of @configuration + @AutoConfigureBefore for correct auto-configuration ordering - Add @ConditionalOnBean(KafkaProperties.class) to gracefully skip when Spring Kafka auto-config is excluded - Use per-property Binder.bind().isBound() for reliable relaxed binding support (camelCase, kebab-case, underscore) instead of Map.containsKey() - Check isSpringPropertyBound("bootstrap-servers") for bootstrap servers since KafkaProperties defaults to ["localhost:9092"] - Fix BinderKeyFormatTest to be a proper regression test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the review @davsclaus! We've addressed your feedback and also fixed several issues found during an in-depth code review: Review fixes (latest commit):
Regarding your suggestions:
|
Users can set camel.component.kafka.bridge-spring-kafka-properties=false to disable the bridge. Enabled by default. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Added the toggle in the latest commit. The bridge can be disabled with: camel.component.kafka.bridge-spring-kafka-properties=falseIt's enabled by default ( |
|
What about |
|
@davidkarlsen can you create a JIRA about Spring Kafka Transaction support for camel-kafka |
Yes this PR
Add this to the 4.21 migration guide (4.19 and 4.20 has been released) @gnodet ^^^^ |
|
@Croway have you seen this PR. The spring-boot kafka starter is added as optional=true dependency. Which would be needed for this PR. Though the con could be that we have a Camel vs SB kafka client misalignment and a classpath problem. But that can happen anyway today. And I guess if I recall correct optional=true then the SB kafka JARs are not loaded by default by maven, and wont be in the end user app. |
|
@davsclaus exactly, the PR is fine, I was even thinking to remove the optional=true, and always import I just tested the version alignments and I confirm that the Kafka client version is aligned by the Spring Boot BOM. For example, camel 4.18.1 declares kafka 3.9.x. The Spring Boot version used in Camel Spring Boot 4.18.1, declares kafka 3.8.x, that is the version that camel spring boot users uses at runtime. I'll create an issue to harden the tests and CI so that we might be able to catch potential API changes and misalignments. |
|
will do, I'll provide an entry in the 4.21 upgrade guide. EDIT: apache/camel#22786 |
… bridge (#22786) Depends on apache/camel-spring-boot#1709 being merged first.
Summary
When using
camel-kafka-starterwith Spring Boot, users previously had to duplicate their Kafka configuration under bothspring.kafka.*andcamel.component.kafka.*properties. This PR adds automatic bridging so that Spring Boot's standard Kafka properties are picked up by the Camel Kafka component.Properties bridged
spring.kafka.*)camel.component.kafka.*)bootstrap-serversbrokersclient-idclient-idsecurity.protocolsecurity-protocolconsumer.group-idgroup-idssl.key-store-locationssl-keystore-locationssl.key-store-passwordssl-keystore-passwordssl.key-store-typessl-keystore-typessl.key-passwordssl-key-passwordssl.trust-store-locationssl-truststore-locationssl.trust-store-passwordssl-truststore-passwordssl.trust-store-typessl-truststore-typessl.protocolssl-protocolproperties[sasl.mechanism]sasl-mechanismproperties[sasl.jaas.config]sasl-jaas-configproperties[sasl.kerberos.service.name]sasl-kerberos-service-nameDesign
Binderto detect whichcamel.component.kafka.*properties the user explicitly setcamel.component.kafka.*settings always take precedence@AutoConfigureBefore(KafkaComponentAutoConfiguration.class)ensures bridging happens before the generated auto-configuration copies properties to the component@ConditionalOnClass(KafkaProperties.class)ensures it only activates whenspring-boot-kafkais on the classpath (optional dependency)Test plan
🤖 Generated with Claude Code