-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic.js
41 lines (36 loc) · 876 Bytes
/
topic.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
// Init requierd dependencies
const { Kafka } = require('kafkajs');
// Init kafka
run();
async function run() {
try {
// Establish TCP connection
const kafka = new Kafka({
clientId: process.env.CLIENT_ID,
brokers: [process.env.KAFKA_CONNECTION],
});
// Create admin
const admin = kafka.admin();
// Connect
console.log('Connecting...');
await admin.connect();
console.log('Connected');
// Create topics
await admin.createTopics({
topics: [
{
topic: process.env.TOPIC_NAME,
numPartitions: process.env.NUM_PARTITIONS,
},
],
});
console.log('Toipcs created successfully');
// Disconnect
await admin.disconnect();
console.log('Disconnected');
} catch (ex) {
console.error(`Something went wrong ${ex}`);
} finally {
process.exit(0);
}
}