-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
25 lines (21 loc) · 735 Bytes
/
Copy pathworker.js
File metadata and controls
25 lines (21 loc) · 735 Bytes
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
'use strict'
var Kafka = require('no-kafka');
var consumer = new Kafka.SimpleConsumer({
idleTimeout: 1000,
clientId: 'sample-consumer',
connectionString: process.env.KAFKA_URL.replace(/\+ssl/g,''),
ssl: {
cert: process.env.KAFKA_CLIENT_CERT || '.ssl/client.crt',
key: process.env.KAFKA_CLIENT_CERT_KEY || '.ssl/client.key'
}
});
console.log("Kafka consumer has been started");
var dataHandler = function (messageSet, topic, partition) {
messageSet.forEach(function (m) {
console.log(topic, partition, m.offset, m.message.value.toString('utf8'));
});
};
return consumer.init().then(function() {
var topic = process.env.KAFKA_PREFIX + process.env.KAFKA_TOPIC
consumer.subscribe(topic, dataHandler);
});