1.0.2 • Published 6 years ago

loopback-kafka-consumer-middleware v1.0.2

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
6 years ago

NPM

Loopback kafka consumer middleware

This is a simple middleware listening for kafka events on a speficied topic.

INSTALL

  npm install loopback-kafka-consumer-middleware --save

SERVER CONFIG

Add the middleware to your middleware.json:

{
  "loopback-kafka-consumer-middleware": {
    "params": {
      "consumerHandler": "./kafkaEventHandler"
    }
  }
}

HANDLER

You need to define an event handler (in the previous example config, kafkaEventHandler.js) with the following structure in the loopback server directory.

'use strict';

module.exports = {
  onMessage: function(message) {
    console.log('Msg: ' + JSON.stringify(message));
  },
  onError: function(err) {
    console.log(err);
  },
  onOffsetOutOfRange: function(err) {
    console.log(err);
  },
};

CONNEXIONS

To be able to connect to your kafka host or zookeeper host and listen for events in the topic, you have to set the KAFKA_URL and KAFKA_TOPIC env variables

export KAFKA_URL=192.168.99.100:2181
export KAFKA_TOPIC=node-test

LICENSE

Apache-2.0