如何在 apache kafka 中创建主题? [英] How to create topics in apache kafka?

查看:34
本文介绍了如何在 apache kafka 中创建主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 kafka 中创建主题的最佳方式是什么?

What is the bestway to create topics in kafka?

  • 创建主题时要定义多少个副本/分区?

在新的生产者 API 中,当我尝试向不存在的主题发布消息时,它第一次失败然后成功发布.

In the new producer API, when i try to publish a message to a non existing topic , it first time fails and then successfully publishing.

  • 我想知道副本、分区和集群节点数之间的关系.
  • 我们需要在发布消息之前创建主题吗?

推荐答案

当您启动 Kafka 代理时,您可以在 conf/server.properties 文件中定义一组属性.该文件只是键值属性文件.属性之一是 auto.create.topics.enable,如果它设置为 true(默认情况下),当您向不存在的主题发送消息时,Kafka 将自动创建主题.

When you are starting your Kafka broker you can define set of properties in conf/server.properties file. This file is just key value property file. One of the properties is auto.create.topics.enable, if it's set to true (by default) Kafka will create topics automatically when you send messages to non-existing topics.

您可以找到的所有配置选项都在此处定义.恕我直言,创建主题的简单规则如下:副本数不能超过您拥有的节点数.主题和分区的数量不受集群中节点数量的影响

All config options you can find are defined here. IMHO, a simple rule for creating topics is the following: number of replicas cannot be more than the number of nodes that you have. Number of topics and partitions is unaffected by the number of nodes in your cluster

例如:

  • 您有 9 个节点的集群
  • 您的主题可以有 9 个分区和 9 个副本,或者18 个分区和 9 个副本或36 个分区和 9 个副本等等...

这篇关于如何在 apache kafka 中创建主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆