-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer.js
36 lines (30 loc) · 870 Bytes
/
producer.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");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
async function init() {
const producer = kafka.producer();
console.log("Connecting Producer");
await producer.connect();
console.log("Producer Connected Successfully");
rl.setPrompt("> ");
rl.prompt();
rl.on("line", async function (line) {
const [companyId, channelId, skuCode, inv] = line.split(" ");
await producer.send({
topic: "inv-updates",
messages: [
{
partition: companyId > 3000 ? 0 : 1,
key: "inventory-update",
value: JSON.stringify({ company: companyId, channelId:channelId, skuCode:skuCode, inv:inv }),
},
],
});
}).on("close", async () => {
await producer.disconnect();
});
}
init();