我想在kafka服务器上创建新主题但在此之前我想从我的服务器检索主题列表,一旦建立连接,我怎样才能实现?
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);
答案 0 :(得分:1)
使用kafka-node
无法直接实现此目的,但您可以使用node-zookeeper-client
执行此操作。如果您已实例kafka.Client
,则您已有权访问zookeeper
客户端。你可以这样做:
client.zk.client.getChildren("/brokers/topics", (err, children, stats) => {
children.forEach(child => console.log(child));
});