From 4161f875ede0446ab1d485730c51e6a2c5baa37a Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Fri, 28 Aug 2020 12:18:53 -0400 Subject: [PATCH] Change default replication factor to -1 (#956) * Change default replication factor to -1 Binder now uses a default value of -1 for replication factor signaling the broker to use defaults. Users who are on Kafka brokers older than 2.4, need to set this to the previous default value of 1 used in the binder. In either case, if there is an admin policy that requires replication factor > 1, then that value must be used instead. Resolves https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/808 * Addressing PR review comments --- docs/src/main/asciidoc/overview.adoc | 10 +++++++--- .../properties/KafkaBinderConfigurationProperties.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/src/main/asciidoc/overview.adoc b/docs/src/main/asciidoc/overview.adoc index a9bbb7ff5..9666ad9ad 100644 --- a/docs/src/main/asciidoc/overview.adoc +++ b/docs/src/main/asciidoc/overview.adoc @@ -106,7 +106,11 @@ spring.cloud.stream.kafka.binder.replicationFactor:: The replication factor of auto-created topics if `autoCreateTopics` is active. Can be overridden on each binding. + -Default: `1`. +NOTE: If you are using Kafka broker versions prior to 2.4, then this value should be set to at least `1`. +Starting with version 3.0.8, the binder uses `-1` as the default value, which indicates that the broker 'default.replication.factor' property will be used to determine the number of replicas. +Check with your Kafka broker admins to see if there is a policy in place that requires a minimum replication factor, if that's the case then, typically, the `default.replication.factor` will match that value and `-1` should be used, unless you need a replication factor greater than the minimum. ++ +Default: `-1`. spring.cloud.stream.kafka.binder.autoCreateTopics:: If set to `true`, the binder creates new topics automatically. If set to `false`, the binder relies on the topics being already configured. @@ -277,7 +281,7 @@ topic.replication-factor:: The replication factor to use when provisioning topics. Overrides the binder-wide setting. Ignored if `replicas-assignments` is present. + -Default: none (the binder-wide default of 1 is used). +Default: none (the binder-wide default of -1 is used). pollTimeout:: Timeout used for polling in pollable consumers. + @@ -373,7 +377,7 @@ topic.replication-factor:: The replication factor to use when provisioning topics. Overrides the binder-wide setting. Ignored if `replicas-assignments` is present. + -Default: none (the binder-wide default of 1 is used). +Default: none (the binder-wide default of -1 is used). useTopicHeader:: Set to `true` to override the default binding destination (topic name) with the value of the `KafkaHeaders.TOPIC` message header in the outbound message. If the header is not present, the default binding destination is used. diff --git a/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java b/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java index 704f46e05..e64faa242 100644 --- a/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java +++ b/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java @@ -92,7 +92,7 @@ public class KafkaBinderConfigurationProperties { private String requiredAcks = "1"; - private short replicationFactor = 1; + private short replicationFactor = -1; private int minPartitionCount = 1;