Giter Club home page Giter Club logo

nestjs-rdkafka's Introduction

nestjs-rdkafka

NPM

npm version Build Status npm npm bundle size
Maintainability Test Coverage

Description

A NestJS module wrapper for node-rdkafka.

Installation

npm i nestjs-rdkafka

Basic usage

Initialize module with configuration of consumer, producer or admin client respectively. A full list of configuration can be found on node-rdkafka's Configuration section.

app.module.ts

import { Module } from "@nestjs/common";
import { TypegooseModule } from "nestjs-typegoose";
import { CatsModule } from "./cat.module.ts";

@Module({
  imports: [
    KafkaModule.forRootAsync({
        consumer: {
            conf: {
                'group.id': 'kafka_consumer',
                'metadata.broker.list': '127.0.0.1:9092'
            }
        },
        producer: {
            conf: {
                'client.id': 'kafka_prducer',
                'metadata.broker.list': '127.0.0.1:9092'
            }
        },
        adminClient: {
            conf: {
                'metadata.broker.list': '127.0.0.1:9092'
            }
        }
    }),
    CatsModule,
  ],
})
export class ApplicationModule {}

Inject the kafka.service in other provider/service to get the consumer, producer and or client.

cats.service.ts

import { Injectable } from "@nestjs/common";
import { KafkaService } from '@a97001/nestjs-rdkafka';

@Injectable()
export class CatsService {
  constructor(
    private readonly kafkaService: KafkaService
  ) {
      const consumer = this.kafkaService.getConsumer(); // consumer

      const producer = this.kafkaService.getProducer(); // producer

      const adminClient = this.kafkaService.getAdminClient(); // admin client

      /* Throw Error if you get any of these without configuration in module initialization */
  }
}

Disconnect

All clients will be automatically disconnected from Kafka onModuleDestroy. You can manually disconnect by calling:

await this.kafkaService.disconnect();

License

nestjs-rdkafka is MIT licensed.

nestjs-rdkafka's People

Contributors

a97001 avatar semantic-release-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

nestjs-rdkafka's Issues

Are contribution accepted?

Hello @a97001 ,

I came across your repository and I found it really interesting as an alternative at the KafkaJs implementation used natively by NestJs. Then I saw the last commit and I saw it to be 4 years ago. I was wondering to make a contribution to move everything to a more recent version both for nestjs and node-rdkafka but, before start, I would like to know if may be interested to merge it once ready.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.