kafkajs/list-topic.js

22 lines
389 B
JavaScript
Raw Normal View History

2023-04-12 17:42:55 +00:00
const { Kafka } = require('kafkajs');
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['localhost:9092']
});
const admin = kafka.admin();
async function listTopic() {
try {
const list = await admin.listTopics()
console.log(list);
} catch (error) {
console.error('Error creating topic:', error);
} finally {
await admin.disconnect();
}
}
listTopic();