Commit 868cc4e1 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add KafkaAdmin Auto Configuration"

Closes gh-10309
parent 3e1d9fa8
...@@ -108,7 +108,7 @@ public class KafkaAutoConfiguration { ...@@ -108,7 +108,7 @@ public class KafkaAutoConfiguration {
@ConditionalOnMissingBean(KafkaAdmin.class) @ConditionalOnMissingBean(KafkaAdmin.class)
public KafkaAdmin kafkaAdmin() { public KafkaAdmin kafkaAdmin() {
KafkaAdmin kafkaAdmin = new KafkaAdmin(this.properties.buildAdminProperties()); KafkaAdmin kafkaAdmin = new KafkaAdmin(this.properties.buildAdminProperties());
kafkaAdmin.setFatalIfBrokerNotAvailable(this.properties.getAdmin().isFailIfNoBrokers()); kafkaAdmin.setFatalIfBrokerNotAvailable(this.properties.getAdmin().isFailFast());
return kafkaAdmin; return kafkaAdmin;
} }
......
...@@ -673,15 +673,14 @@ public class KafkaProperties { ...@@ -673,15 +673,14 @@ public class KafkaProperties {
private String clientId; private String clientId;
/** /**
* Additional producer-specific properties used to configure the client. * Additional admin-specific properties used to configure the client.
*/ */
private final Map<String, String> properties = new HashMap<>(); private final Map<String, String> properties = new HashMap<>();
/** /**
* When true, the application context will not load if the broker connection * Fail fast if the broker is not available on startup.
* fails when attempting to provision topics.
*/ */
private boolean failIfNoBrokers; private boolean failFast;
public Ssl getSsl() { public Ssl getSsl() {
return this.ssl; return this.ssl;
...@@ -695,12 +694,12 @@ public class KafkaProperties { ...@@ -695,12 +694,12 @@ public class KafkaProperties {
this.clientId = clientId; this.clientId = clientId;
} }
public boolean isFailIfNoBrokers() { public boolean isFailFast() {
return this.failIfNoBrokers; return this.failFast;
} }
public void setFailIfNoBrokers(boolean failIfNoBrokers) { public void setFailFast(boolean failFast) {
this.failIfNoBrokers = failIfNoBrokers; this.failFast = failFast;
} }
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
......
...@@ -177,7 +177,7 @@ public class KafkaAutoConfigurationTests { ...@@ -177,7 +177,7 @@ public class KafkaAutoConfigurationTests {
public void adminProperties() { public void adminProperties() {
load("spring.kafka.clientId=cid", load("spring.kafka.clientId=cid",
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
"spring.kafka.admin.fail-if-no-brokers=true", "spring.kafka.admin.fail-fast=true",
"spring.kafka.admin.properties.fiz.buz=fix.fox", "spring.kafka.admin.properties.fiz.buz=fix.fox",
"spring.kafka.admin.ssl.key-password=p4", "spring.kafka.admin.ssl.key-password=p4",
"spring.kafka.admin.ssl.keystore-location=classpath:ksLocP", "spring.kafka.admin.ssl.keystore-location=classpath:ksLocP",
......
...@@ -939,9 +939,8 @@ content into your application; rather pick only the properties that you need. ...@@ -939,9 +939,8 @@ content into your application; rather pick only the properties that you need.
spring.jms.template.time-to-live= # Time-to-live of a message when sending in milliseconds. Enable QoS when set. spring.jms.template.time-to-live= # Time-to-live of a message when sending in milliseconds. Enable QoS when set.
# APACHE KAFKA ({sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[KafkaProperties]) # APACHE KAFKA ({sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[KafkaProperties])
spring.kafka.admin.bootstrap-servers= # Comma-delimited list of host:port pairs to use for establishing the initial connection to the Kafka cluster.
spring.kafka.admin.client-id= # Id to pass to the server when making requests; used for server-side logging. spring.kafka.admin.client-id= # Id to pass to the server when making requests; used for server-side logging.
spring.kafka.admin.fail-if-no-brokers=false # When true, the application context will not load if the broker connection fails when attempting to provision topics. spring.kafka.admin.fail-fast=false # Fail fast if the broker is not available on startup.
spring.kafka.admin.properties.*= # Additional admin-specific properties used to configure the client. spring.kafka.admin.properties.*= # Additional admin-specific properties used to configure the client.
spring.kafka.admin.ssl.key-password= # Password of the private key in the key store file. spring.kafka.admin.ssl.key-password= # Password of the private key in the key store file.
spring.kafka.admin.ssl.keystore-location= # Location of the key store file. spring.kafka.admin.ssl.keystore-location= # Location of the key store file.
......
...@@ -4816,20 +4816,14 @@ Kafka configuration is controlled by external configuration properties in ...@@ -4816,20 +4816,14 @@ Kafka configuration is controlled by external configuration properties in
spring.kafka.consumer.group-id=myGroup spring.kafka.consumer.group-id=myGroup
---- ----
TIP: To create a topic on startup, simply add a bean of type `NewTopic`. If the topic
already exists, the related bean is ignored.
See {sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[`KafkaProperties`] See {sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[`KafkaProperties`]
for more of the supported options. for more of the supported options.
[[boot-features-kafka-topics]]
==== Creating Topics
Spring Boot auto configuration will add a `KafkaAdmin` bean to the application context.
This bean will automatically create a topic for each `NewTopic` bean in the application context.
Topics can only be added with this technique, not modified; if a topic already exists, the `NewTopic` bean is ignored.
[[boot-features-kafka-sending-a-message]] [[boot-features-kafka-sending-a-message]]
==== Sending a Message ==== Sending a Message
Spring's `KafkaTemplate` is auto-configured and you can autowire them directly in your own Spring's `KafkaTemplate` is auto-configured and you can autowire them directly in your own
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment