Kafka Streams 复制因子不适用于状态存储更改日志主题

Kafka Streams replication factor not applied to state store changelog topics

我们通过 Spring Cloud Stream 集成使用 Kafka Streams。我通过设置

配置了要在所有内部 Kafka Streams 主题中使用的复制因子
spring.cloud.stream.kafka.streams.binder.configuration.replication.factor=${REPL_FACTOR}

它适用于 Kafka Streams 内部使用的大多数 repartition/changelog 主题。但是,此设置似乎对通过 Materialized#as(StoreSupplier) 手动创建的状态存储更改日志主题没有影响。对于那些主题,我仍然可以看到复制因子设置为默认值 1。也无法使用 Materialized#withLoggingEnabled(Map<String, String>) 设置它,因为它只接受主题级别的配置(replication.factor 是 Streams 配置)。这是 Kafka Streams 中的已知错误吗?我找不到任何东西。如果是这样,是否有解决方法来增加这些更改日志主题的复制因子?

我们在代理端使用 Kafka v2.3.1,在客户端使用 2.5.0。

从2.4版本开始,AdminClient现在可以在NewTopic中将复制因子设置为-1,这意味着在创建主题时应该使用default.replication.factor-KIP-464.

但是,Kafka Streams 目前似乎没有使用此功能;有一个未解决的问题 KAFKA-8531

您可以使用

设置内部主题的复制因子
StreamsConfig.REPLICATION_FACTOR_CONFIG)

https://kafka.apache.org/documentation/#replication.factor

The replication factor for change log topics and repartition topics created by the stream processing application.

由于您是通过活页夹配置进行设置的,因此它应该会按预期工作。

编辑

您使用的 spring-cloud-stream 是什么版本?我刚刚用 3.0.8 测试过,它按预期工作。

spring.cloud.stream.kafka.streams.binder.configuration.replication.factor: 3

2020-10-15 12:03:55,601 ERROR [kafka-stre] o.a.k.s.p.i.StreamThread:673 - stream-thread [kafka-streams-inventory-processor-b8d07a5a-f3c4-476a-a265-119163d2acb7-StreamThread-1] Encountered the following unexpected Kafka exception during processing, this usually indicate Streams internal errors: org.apache.kafka.streams.errors.StreamsException: Could not create topic kafka-streams-inventory-processor-inventory-counts-changelog.

Caused by: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 1.