Skip to content Skip to sidebar Skip to footer

How Can I Get List Of Topics From Kafka Server Using Kafka-node Library?

I wanted to create new topic on kafka server but before that i want to retrieve topic list from my server , How can i achieve that once connection is established ? main.js var gr

Solution 1:

No real direct way to do this with kafka-node, but you can do it with node-zookeeper-client. If you have a kafka.Client instantiated, you already have access to a zookeeper client. You can just do:

client.zk.client.getChildren("/brokers/topics", (err, children, stats) => {
  children.forEach(child =>console.log(child));
});

Solution 2:

This is old question but after searching an answer for that I found out that there is a more proper api in kafka node:

const client = new kafka.KafkaClient();
const admin = new kafka.Admin(client);
admin.listTopics((err, res) => {
  console.log('topics', res);
});

https://github.com/SOHU-Co/kafka-node#listtopicscb

Post a Comment for "How Can I Get List Of Topics From Kafka Server Using Kafka-node Library?"