Search code examples
node.jsapache-kafkakafka-node

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:

Solution

  • 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]