diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java index b710bf1ca9..cf6c4dd34c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java @@ -96,11 +96,12 @@ public class KafkaAutoConfiguration { @Bean @ConditionalOnMissingBean(ProducerFactory.class) public ProducerFactory kafkaProducerFactory() { - DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>( + DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>( this.properties.buildProducerProperties()); - KafkaProperties.Producer producer = this.properties.getProducer(); - if (producer.getTransactionIdPrefix() != null) { - factory.setTransactionIdPrefix(producer.getTransactionIdPrefix()); + String transactionIdPrefix = this.properties.getProducer() + .getTransactionIdPrefix(); + if (transactionIdPrefix != null) { + factory.setTransactionIdPrefix(transactionIdPrefix); } return factory; } @@ -108,7 +109,8 @@ public class KafkaAutoConfiguration { @Bean @ConditionalOnProperty(name = "spring.kafka.producer.transaction-id-prefix") @ConditionalOnMissingBean - public KafkaTransactionManager kafkaTransactionManager(ProducerFactory producerFactory) { + public KafkaTransactionManager kafkaTransactionManager( + ProducerFactory producerFactory) { return new KafkaTransactionManager<>(producerFactory); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java index 71ebe1dbec..55e960a631 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java @@ -521,7 +521,7 @@ public class KafkaProperties { private Integer retries; /** - * When non empty, enables transactional support for producer. + * When non empty, enables transaction support for producer. */ private String transactionIdPrefix; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index e9e39f1a8d..1fb5e66a84 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -200,9 +200,8 @@ public class KafkaAutoConfigurationTests { assertThat( context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)) .isEmpty(); - assertThat( - context.getBeansOfType(KafkaTransactionManager.class)) - .isEmpty(); + assertThat(context.getBeansOfType(KafkaTransactionManager.class)) + .isEmpty(); assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz"); assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox"); }); @@ -303,8 +302,7 @@ public class KafkaAutoConfigurationTests { assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo"); assertThat(dfa.getPropertyValue("controlFlag")).isEqualTo( AppConfigurationEntry.LoginModuleControlFlag.REQUISITE); - assertThat( - context.getBeansOfType(KafkaTransactionManager.class)) + assertThat(context.getBeansOfType(KafkaTransactionManager.class)) .hasSize(1); assertThat(((Map) dfa.getPropertyValue("options"))) .containsExactly(entry("useKeyTab", "true")); diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index ec433f382e..ea907afe4f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -998,6 +998,7 @@ content into your application; rather pick only the properties that you need. spring.kafka.producer.ssl.keystore-password= # Store password for the key store file. spring.kafka.producer.ssl.truststore-location= # Location of the trust store file. spring.kafka.producer.ssl.truststore-password= # Store password for the trust store file. + spring.kafka.producer.transaction-id-prefix= # When non empty, enables transaction support for producer. spring.kafka.producer.value-serializer= # Serializer class for values. spring.kafka.properties.*= # Additional properties, common to producers and consumers, used to configure the client. spring.kafka.ssl.key-password= # Password of the private key in the key store file.