How to use the kafka-node.Client function in kafka-node

To help you get started, we’ve selected a few kafka-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github speedd-project / speedd / speedd_ui_bf_new / app.js View on Github external
function setKafka(){
	/// setting up kafka consummer
	console.log("Setting up Kafka clients");
	
	Consumer = kafka.Consumer;
	client = new kafka.Client('zk:2181/');
	consumer = new Consumer(
		client, 
		// payloads
			[{ topic: 'speedd-fraud-actions', partition: 0, offset: 0 },
			 { topic: 'speedd-fraud-out-events', partition: 0, offset: 0 }
			 ],
		// options
		{fromOffset: true} // true = read messages from beginning
	);

	//// Setting up Kafka Producer

	Producer = kafka.Producer;
	producer = new Producer(client);

	producer.on('ready', function () {
github speedd-project / speedd / speedd-ui / app.js View on Github external
function setKafka(){
	/// setting up kafka consummer
	console.log("Setting up Kafka clients");
	
	Consumer = kafka.Consumer;
	client = new kafka.Client('localhost:2181/');
	consumer = new Consumer(
		client, 
		// payloads
			[{ topic: 'speedd-traffic-actions', partition: 0, offset: 0 },
			 { topic: 'speedd-traffic-out-events', partition: 0, offset: 0 }
			 ],
		// options
		{fromOffset: true} // true = read messages from beginning
	);

	//// Setting up Kafka Producer

	Producer = kafka.Producer;
	producer = new Producer(client);
	payloads = [
			{ topic: 'speedd-out-events', messages: 'THIS IS THE NEW APP', partition: 0 }
github speedd-project / speedd / speedd_ui_bf / app.js View on Github external
function setKafka(){
	/// setting up kafka consummer
	console.log("Setting up Kafka clients");
	
	Consumer = kafka.Consumer;
	client = new kafka.Client('localhost:2181/');
	consumer = new Consumer(
		client, 
		// payloads
			[{ topic: 'speedd-fraud-actions', partition: 0, offset: 0 },
			 { topic: 'speedd-fraud-out-events', partition: 0, offset: 0 },
			 { topic: 'speedd-fraud-in-events', partition: 0, offset: 0 }
			 ],
		// options
		{fromOffset: true} // true = read messages from beginning
	);

	//// Setting up Kafka Producer

	Producer = kafka.Producer;
	producer = new Producer(client);
	payloads = [
github lucasjellema / microservices-choreography-kubernetes-workshop-june2017 / part3 / event-bus-listener / EventBusListener.js View on Github external
function initializeKafkaConsumer(attempt) {
  try {
    console.log("Try to initialize Kafka Client and Consumer, attempt " + attempt);
    var client = new kafka.Client(kafkaHost + ":"+zookeeperPort+"/")
    console.log("created client for " + kafkaHost);
    consumer = new Consumer(
      client,
      [],
      { fromOffset: true }
    );
    console.log("Kafka Client and Consumer initialized " + consumer);
    // register the handler for any messages received by the consumer on any topic it is listening to. 
    consumer.on('message', function (message) {
      console.log("event received");
      handleEventBusMessage(message);
    });
    consumer.on('error', function (err) {
      console.log("error in creation of Kafka consumer " + JSON.stringify(err));
      console.log("Try again in 5 seconds");
      setTimeout(initializeKafkaConsumer, 5000, attempt + 1);
github deepstreamIO / deepstream.io-msg-kafka / src / message-connector.js View on Github external
constructor(config) {
    super()

    this.name = pckg.name
    this.version = pckg.version

    this.isReady = false
    this._topics = []

    this._validateConfig(config)
    this._clientId = config.clientId || (Math.random() * 1e32).toString(36)

    this._client = new kafka.Client(config.connectionString)

    this._producer = new kafka.Producer(this._client)
    this._producer.on('ready', () => {
      this.isReady = true
      this.emit('ready')
    })
    this._producer.on('error', this._onError.bind(this))

    this._consumer = new kafka.Consumer(this._client, [])
    this._consumer.on('message', this._onMessage.bind(this))
    this._consumer.on('error', this._onError.bind(this))
    this._consumer.on('offsetOutOfRange', this._onError.bind(this))
  }
github mikfreeman / chatme_kafka / lib / kafka_producer.js View on Github external
var kafka = require('kafka-node'),
    HighLevelProducer = kafka.HighLevelProducer,
    client = new kafka.Client(),
    producer = new HighLevelProducer(client);

module.exports = function(chatServer) {

    producer.on('ready', function () {
        chatServer.on('sendMessage', function (message) {

            var messageString = JSON.stringify(message);
            console.log('Sending message ' + messageString );

            var kafkaMessage = {
                topic: 'chatmessages',
                messages : messageString
            };

            producer.send([kafkaMessage], function (err, data) {
github egovernments / egov-services / rainmaker / firenoc-services / src / kafka / producer.js View on Github external
var kafka = require("kafka-node");
import envVariables from "../envVariables";

const Producer = kafka.Producer;
let client;

if (process.env.NODE_ENV === "development") {
  client = new kafka.Client();
  console.log("local Producer- ");
} else {
  client = new kafka.KafkaClient({ kafkaHost: envVariables.KAFKA_BROKER_HOST });
  console.log("cloud Producer- ");
}

const producer = new Producer(client);

producer.on("ready", function() {
  console.log("Producer is ready");
});

producer.on("error", function(err) {
  console.log("Producer is in error state");
  console.log(err);
});
github SciSpike / yaktor / bin / kafka / config / global / 02_kafka.js View on Github external
function createProducer (next) {
      var opts = yaktor.kafka.client
      client = new kafka.Client(opts.connectionString, opts.clientId, opts.zkOptions, opts.noAckBatchOptions, opts.sslOptions)
      producer = new kafka.Producer(client, yaktor.kafka.producer)
      producer.once('ready', next)
      producer.once('error', next)
    },
    function resetErrorListeners (next) {
github SomeKittens / gustav / couplers / GustavKafka.ts View on Github external
getClient(): any {
    return new kafka.Client(this.config.connString, this.config.clientId);
  }
github telepat-io / telepat-worker / lib / kafka_client.js View on Github external
var KafkaClient = function(name, config){
	MessagingClient.call(this, name, config);
	this.connectionClient = kafka.Client(config.host+':'+config.port+'/', name);

	this.kafkaConsumer = new kafka.HighLevelConsumer(this.connectionClient, [{topic: config.topic}], {groupId: config.topic});
	this.kafkaConsumer.on('error', function() {});
	this.kafkaProducer = new kafka.HighLevelProducer(this.connectionClient);
	this.kafkaProducer.on('error', function() {});
};