栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Kafaka报错:Creating topics with default partitions/replication factor are only supported in CreateTopi

Kafaka报错:Creating topics with default partitions/replication factor are only supported in CreateTopi

背景

项目基本信息
  • Spring Cloud:Hoxton.SR10
  • Spring Boot:2.3.9.RELEASE
  • 之前升级过版本:Greenwich.SR2,2.1.6.RELEASE

报错信息

项目里新增了一个Kafka的Topic,结果启动的时候报错:

org.springframework.cloud.stream.binding.BindingService [330] -| Failed to create producer binding; retrying in 30 seconds

org.springframework.cloud.stream.provisioning.ProvisioningException: Provisioning exception encountered for drug-standard-batch-update-message-output; nested exception is org.apache.kafka.common.errors.UnsupportedVersionException: Creating topics with default partitions/replication factor are only supported in CreateTopicRequest version 4+. The following topics need values for partitions and replicas: [xxx-xxxx]

Kafka的配置如下:

spring:
  cloud:
    stream:
      default-binder: kafka
      default:
        producer:
          headerMode: embeddedHeaders
        consumer:
          concurrency: 3
          resetOffsets: true
          auto:
            offset:
              reset: latest
          headerMode: embeddedHeaders
      kafka:
        binder:
          reset-offset: true
          start-offset: latest
          min-partition-count: 3
          auto-create-topics: true
          auto-add-partitions: true
          configuration:
            max.request.size: 20000000       
          brokers:
            - 172.xx.xx.1:9092
            - 172.xx.xx.2:9092
            - 172.xx.xx.3:9092
    

分析

在Github上找到一个bug:但是解决的代码又不是Kafka的

https://github.com/vectorizedio/redpanda/issues/292

那我们来分析下提示信息:

Creating topics with default partitions/replication factor are only supported in CreateTopicRequest version 4+. The following topics need values for partitions and replicas

问题在于使用了partitions或者replication的默认配置 ?从上面的配置来看,已经自动创建Topic,并自动创建分区(最小分区数量是3),但是没有对副本数量进行配置。那么则说明副本配置应该使用的是默认配置。

参考自《Spring Cloud微服务实战》:下面的配置是Brixton.SR5版本的配置,可以看到有个replicationFactor参数可以配置副本数量,且默认值为1。

再去查询最新的官方文档:https://github.com/spring-cloud/spring-cloud-stream-binder-kafka

发现在3.0.8版本及以后,这个值的默认值就变成了-1。言下之意就是使用kafka自己的default.replication.factor配置。所以原因就在这里,Spring Cloud版本升级后,这个默认值由1变成了-1。从而出现了问题。

解决

那么解决办法就是指定spring.cloud.stream.kafka.binder.replication-factor。

spring:
  cloud:
    stream:
      default-binder: kafka
      default:
        producer:
          headerMode: embeddedHeaders
        consumer:
          concurrency: 3
          resetOffsets: true
          auto:
            offset:
              reset: latest
          headerMode: embeddedHeaders
      kafka:
        binder:
          reset-offset: true
          start-offset: latest
          min-partition-count: 3
          auto-create-topics: true
          auto-add-partitions: true
          # 指定topic的副本数量
          replication-factor: 1
          configuration:
            max.request.size: 20000000       
          brokers:
            - 172.xx.xx.1:9092
            - 172.xx.xx.2:9092
            - 172.xx.xx.3:9092

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/583931.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号