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

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料