-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.js
36 lines (28 loc) · 819 Bytes
/
admin.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
const kafka = require('./client')
async function init() {
/**
* Admin is in charge of creating topics and partitions on the kafka service according to which the producers
* will send messages and consumers will consume the data
*/
const admin = kafka.admin()
// Connect the admin to the service
console.log('Connecting Admin...')
await admin.connect()
console.log('Successfully connected admin.')
// Create topic
console.log('Creating topic: [rider-updates]...')
await admin.createTopics({
topics: [
{
topic: 'rider-updates',
numPartitions: 2
}
]
})
console.log('Topic [rider-updates] created successfully.')
// Disconnect admin
console.log('Disconnecting Admin...')
await admin.disconnect()
console.log('Admin disconnected.')
}
init()