kafka不同的topic设置不同的partition

kafka different topics set different partitions

据我所知,kafka server.properties 中的 'num.partitions' 将适用于所有主题。 现在我想为 topicA 设置 partitionNumber=1,为 topicB 设置 partitionNumber=2。 是否可以用高级别实现 api?

num.partitions 是自动生成主题时使用的值。如果是自己生成topic的话,可以设置任意个partitions。

您可以使用以下命令自行生成主题。 (复制因子 3 和分区数 2。大写单词是你必须替换的。)

bin/kafka-topics.sh --create --zookeeper ZOOKEEPER_HOSTNAME:ZOOKEEPER_PORT \
--replication-factor 3 --partitions 2 --topic TOPIC_NAME

有一个可以在 Kafka Broker 上设置的配置值。

auto.create.topics.enable=true

True 实际上是默认设置,

Enable auto creation of topic on the server. If this is set to true then attempts to produce data or fetch metadata for a non-existent topic will automatically create it with the default replication factor and number of partitions.

因此,如果您从一个不存在的分区读取或写入,就像它存在一样,if 会自动为您创建一个。没听说过用高级api自动创建一个。

查看Kafka Protocol Documentation,似乎没有提供创建主题的方法。