Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create kafka topic with partitions in nodejs?

I am using kafka-node link api for creating kafka topics. I did not find how to create a kafka topic with partitions.

var kafka = require('kafka-node'),
    Producer = kafka.Producer,
    client = new kafka.Client(),
    producer = new Producer(client);
// Create topics sync
producer.createTopics(['t','t1'], false, function (err, data) {
    console.log(data);
});
// Create topics async
producer.createTopics(['t'], true, function (err, data) {});

producer.createTopics(['t'], function (err, data) {});// Simply omit 2nd arg

how to create kafka topic with partitions in nodejs.

like image 346
lucy Avatar asked Oct 29 '22 23:10

lucy


1 Answers

From your node.js app execute the shell script $KAFKA_HOME/bin/kafka-topics.sh —create —topic topicname —partitions 8 —replication-factor 1 —zookeeper localhost:2181

Where $KAFKA_HOME is the location where you installed Kafka

like image 65
Hans Jespersen Avatar answered Nov 15 '22 10:11

Hans Jespersen