Polish "Add KafkaAdmin Auto Configuration"

Closes gh-10309
This commit is contained in:
Stephane Nicoll
2017-09-25 14:50:34 +02:00
parent 3e1d9fa856
commit 868cc4e1e0
5 changed files with 13 additions and 21 deletions

View File

@@ -108,7 +108,7 @@ public class KafkaAutoConfiguration {
@ConditionalOnMissingBean(KafkaAdmin.class)
public KafkaAdmin kafkaAdmin() {
KafkaAdmin kafkaAdmin = new KafkaAdmin(this.properties.buildAdminProperties());
kafkaAdmin.setFatalIfBrokerNotAvailable(this.properties.getAdmin().isFailIfNoBrokers());
kafkaAdmin.setFatalIfBrokerNotAvailable(this.properties.getAdmin().isFailFast());
return kafkaAdmin;
}

View File

@@ -673,15 +673,14 @@ public class KafkaProperties {
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<>();
/**
* When true, the application context will not load if the broker connection
* fails when attempting to provision topics.
* Fail fast if the broker is not available on startup.
*/
private boolean failIfNoBrokers;
private boolean failFast;
public Ssl getSsl() {
return this.ssl;
@@ -695,12 +694,12 @@ public class KafkaProperties {
this.clientId = clientId;
}
public boolean isFailIfNoBrokers() {
return this.failIfNoBrokers;
public boolean isFailFast() {
return this.failFast;
}
public void setFailIfNoBrokers(boolean failIfNoBrokers) {
this.failIfNoBrokers = failIfNoBrokers;
public void setFailFast(boolean failFast) {
this.failFast = failFast;
}
public Map<String, String> getProperties() {

View File

@@ -177,7 +177,7 @@ public class KafkaAutoConfigurationTests {
public void adminProperties() {
load("spring.kafka.clientId=cid",
"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.ssl.key-password=p4",
"spring.kafka.admin.ssl.keystore-location=classpath:ksLocP",

View File

@@ -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.
# 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.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.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.

View File

@@ -4816,20 +4816,14 @@ Kafka configuration is controlled by external configuration properties in
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`]
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]]
==== Sending a Message
Spring's `KafkaTemplate` is auto-configured and you can autowire them directly in your own