dongmie3987067 2019-01-20 20:14
浏览 23
已采纳

调用GetMetadata时禁用自动主题创建

I am using confluent golang for my Kafka client. I use AdminClient to create/delete/get topics in kafka cluster. Here is my code to initialize AdminClient

adminClient, err := kafka.NewAdminClient(&kafka.ConfigMap{
    "bootstrap.servers": 127.0.0.1:9092,
})

After that, I use this class to create and get all topics in kafka cluster. Here is the code for creating a topic:

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

results, err := adminClient.CreateTopics(
    ctx,
    []kafka.TopicSpecification{{
        Topic:             topic,
        NumPartitions:     numPartitions,
        ReplicationFactor: replicationFactor}},
    kafka.SetAdminOperationTimeout(TimeOut),
)

After that, I get again topic information:

result, err := adminClient.GetMetadata(&topic, false, 1000)

The problem is: If I get a topic that not existed before, kafka will automatically create that topic. This is a behavior that I don't want. Please tell me how to fix this.

  • 写回答

1条回答 默认 最新

  • doufen1933 2019-01-20 20:26
    关注

    To disable automatic creation of topics, you should update your broker configurations to have auto.create.topics.enable as false. Take a look at the docs or this page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号