简体   繁体   中英

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. I want to create a single topic with 3 partitions. 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. 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.

Because of @mike I got a hint and resolved the issue. I did the following -

remove leader=0 and set all replicas to 0 replicas: [0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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