22 lines
389 B
JavaScript
22 lines
389 B
JavaScript
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();
|