-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.js
41 lines (31 loc) · 852 Bytes
/
consumer.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
const {Kafka} = require("kafkajs")
const groupId = process.argv[2];
run();
async function run(){
try
{
const kafka = new Kafka({
"clientId": "myapp",
"brokers" :["localhost:29092"]
})
const consumer = kafka.consumer({"groupId": groupId})
console.log("Connecting.....")
await consumer.connect()
console.log("Connected!")
await consumer.subscribe({
"topic": "Users",
"fromBeginning": true
})
await consumer.run({
"eachMessage": async result => {
console.log(`RVD Msg ${result.message.value} on partition ${result.partition}`)
}
})
}
catch(ex)
{
console.error(`Something bad happened ${ex}`)
}
finally{
}
}