npm.io
0.1.6 • Published 3 years ago

kafka-connector

Licence
UNLICENSED
Version
0.1.6
Deps
6
Size
13 kB
Vulns
0
Weekly
0

Description

[kafka-connector]A public TypeScript library for easy kafka producer and consumer.

Installation

$ npm i kafka-connector

How to use?

  Step 1 - Initilize KafkaManager, you can use custom host and port.
    this.kafkaManager = await KafkaManager.create(); // 
    await this.kafkaManager.initilize({ host: 'localhost', 'port': 29092});
 Step 2 - Consume existing topic
    await this.kafkaManager.consume(
      { topic: 'customtopic' }, {
      eachMessage: async ({ topic, partition, message }) => {
        console.log({
          topic: topic.toString(),
          partition: partition.toString(),
          value: message.value.toString()
        })
      }
    });
 Step 3 - Produce to existing or new topic
        await kafkaManager.produce({
            topic: 'customtopic', messages: [
                {
                    key: 'create user',
                    value: 'Hi, New event happended!!'
                }
            ]
        })

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Stay in touch

License

Nest is MIT licensed.