Skip to content

Commit

Permalink
KafkaBinderConfigurationProperties metadata
Browse files Browse the repository at this point in the history
When generating configuration metadata (spring-configuration-metadata.json),
KafkaBinderConfigurationProperties class is missing all the information except
for the constructor bound KafkaProperties. We need to add the @Autowired on the
constructor so that Boot will not do a constructor binding and thus include all
the JavaBeans style properties in the metadata. See this Boot issue for more details.

spring-projects/spring-boot#34031

In addition, this @Autowired is necessary for the properties to be correctly
bound when running in native mode.

Resolves #2640
Resolves #2644
  • Loading branch information
sobychacko committed Feb 7, 2023
1 parent bde556a commit 4100f27
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.stream.binder.HeaderMode;
Expand Down Expand Up @@ -144,6 +145,20 @@ public class KafkaBinderConfigurationProperties {
*/
private boolean enableObservation;

/**
* @Autowired on this constructor is necessary in order to make sure that all the optional (provided as JavaBean setters)
* properties in this class are taken into consideration when generating configuration metadata.
* In addition, in order for all the properties to be discovered and bound when running as a native
* application, this @Autowired is necessary, so that Boot binding mechanism considers all the properties.
* See the following issues for more details.
*
* https://github.com/spring-cloud/spring-cloud-stream/issues/2640
* https://github.com/spring-projects/spring-boot/issues/34031
* https://github.com/spring-cloud/spring-cloud-stream/issues/2644
*
* @param kafkaProperties Spring Kafka properties autoconfigured by Spring Boot
*/
@Autowired
public KafkaBinderConfigurationProperties(KafkaProperties kafkaProperties) {
Assert.notNull(kafkaProperties, "'kafkaProperties' cannot be null");
this.kafkaProperties = kafkaProperties;
Expand Down
65 changes: 65 additions & 0 deletions samples/kafka-binder-native-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,69 @@
</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ spring.cloud:
destination: graalUppercaseFunction-in-0
graalLoggingConsumer-in-0:
destination: graalUppercaseFunction-out-0
spring:
kafka:
bootstrap-servers: localhost:9092
kafka:
binder:
brokers: localhost:9092

0 comments on commit 4100f27

Please sign in to comment.