-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka.js
30 lines (24 loc) · 799 Bytes
/
kafka.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
const { Kafka } = require('kafkajs')
const fs = require('fs')
// This creates a client instance that is configured to connect to the Kafka broker provided by
// the environment variable KAFKA_BOOTSTRAP_SERVER
const kafka = new Kafka({
clientId: 'topic_test',
brokers: ['10.120.11.172:9094'],
logLevel: 2
})
const producer = kafka.producer()
producer.on('producer.connect', () => {
console.log(`KafkaProvider: connected`);
});
producer.on('producer.disconnect', () => {
console.log(`KafkaProvider: could not connect`);
});
producer.on('producer.network.request_timeout', (payload) => {
console.log(`KafkaProvider: request timeout ${payload.clientId}`);
});
const run = async () => {
await producer.connect();
};
run().catch(console.error);
module.exports = producer;