我怎样才能得到使用kafka-node库的kafka服务器的主题列表?

我想在kafka服务器上创build新的主题,但在此之前,我想从我的服务器检索主题列表,我怎样才能实现一旦连接build立?

main.js

var groupId = 'test1'; var clientId = "consumer-" + Math.floor(Math.random() * 10000); var options = {autoCommit: true, fetchMaxWaitMs: 100, fetchMaxBytes: 10 * 1024 * 1024, groupId: groupId}; console.log("Started consumer: ", clientId); var consumer_client = new Client(kafkaConn,clientId); var client = new Client(consumer_client.connectionString,clientId); var consumer = new HighLevelConsumer(client, topics, options); 

没有真正的直接的方法来做到这一点与kafka-node ,但你可以做到这一点与node-zookeeper-client 。 如果你有一个kafka.Client实例化,你已经可以访问一个zookeeper客户端。 你可以做:

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