简体   繁体   English

在nodeJS中创建主题时将leader分配给kafka主题的分区

[英]Assign leader to partitions of kafka topic while creating topics in nodeJS

I have single kafka broker and am implementing kafka in nodeJS using kafka-node.我有一个 kafka 代理,并且正在使用 kafka-node 在 nodeJS 中实现 kafka。 I want to create a single topic with 3 partitions.我想创建一个包含 3 个分区的主题。 While doing this, problem occuring is only first partition is getting leader assign where as other two partitions are not getting leaders.这样做时,出现的问题只是第一个分区正在获得领导者分配,而其他两个分区没有获得领导者。 I want to assign leaders to all of the partitions.我想为所有分区分配领导者。 Can anyone please tell me how could I do this?谁能告诉我我怎么能做到这一点? Thanks in advance.提前致谢。

var client = new kafka.KafkaClient();
    var topic = 't-26';
    var topicsToCreate = [
        {
            topic: topic,
            partitions: 3,
            Leader: 0,
            replicationFactor: 1,
            replicaAssignment: [
            {
              partition: 0,
              replicas: [0]
            },
            {
                partition: 1,
                replicas: [1]
            },
            {
                partition: 2,
                replicas: [2]
            }
          ]
        },
        ];
        client.createTopics(topicsToCreate, (error, result) => {
             console.log(result);
        });

Topic created as follows -创建的主题如下 -

Topic: t-26     PartitionCount: 3       ReplicationFactor: 1    Configs:
        Topic: t-26     Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: t-26     Partition: 1    Leader: none    Replicas: 1     Isr:
        Topic: t-26     Partition: 2    Leader: none    Replicas: 2     Isr:

You are "globally" defining the Leader to be on broker with id 0 whereas you want to have the partitions 1 and 2 located on other brokers.您正在“全局”定义领导者位于 ID 为0代理上,而您希望分区12位于其他代理上。 As you defined the replication to be one, this is contradicting itself.当您将复制定义为一个时,这本身就是矛盾的。 Remove the part about the Leader and it should automatically create the partitions leaders on the brokers you want.删除有关Leader的部分,它应该会自动在您想要的代理上创建分区领导者。

Because of @mike I got a hint and resolved the issue.由于@mike,我得到了一个提示并解决了这个问题。 I did the following -我做了以下-

remove leader=0 and set all replicas to 0 replicas: [0]删除leader=0并将所有副本设置为 0 个replicas: [0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM