Created
April 24, 2018 00:56
-
-
Save cantoniazzi/6b93708aae0b0eda39309c1c4ef12887 to your computer and use it in GitHub Desktop.
A kafka client in nodejs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const uuidv4 = require('uuid/v4'); | |
const kafka = require('kafka-node'), | |
Producer = kafka.Producer, | |
client = new kafka.KafkaClient({kafkaHost: 'KAFKA_HOST_HERE'}), | |
producer = new Producer(client); | |
producer.on("ready", function () { | |
console.log("Kafka Producer is connected and ready."); | |
}); | |
module.exports = function kafkaClient(scheduling, cb) { | |
let _guid = uuidv4(); | |
producer.send([{topic: 'KAFKA_TOPIC_HERE', key: _guid, messages: scheduling}], function (err, data){ | |
if (err){ | |
console.log('error kafka: ', err); | |
return cb(err, null); | |
} else { | |
return cb(null, data); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment