-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic-creation.js
42 lines (32 loc) · 907 Bytes
/
topic-creation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { Kafka } = require("kafkajs");
createTopic();
async function createTopic() {
try {
const kafka = new Kafka({
clientId: "kafka_client_1",
brokers: ["10.11.0.96:9092"]
});
const kafkaAdmin = kafka.admin();
console.log("Connecting Apache Kafka...");
await kafkaAdmin.connect();
console.log("Connected to Apache Kafka");
await kafkaAdmin.createTopics({
topics: [
{
topic: "Log1",
numPartitions: 1
},
{
topic: "Log2",
numPartitions: 2
}
]
});
console.log("Topics Created");
await kafkaAdmin.disconnect();
} catch (error) {
console.log(error.message);
} finally {
process.exit(0);
}
}