Narnia's Psychedelic Mushrooms
    Have ideas to improve npm?Join in the discussion! »

    nest-kinesis-producer
    TypeScript icon, indicating that this package has built-in type declarations

    2.4.0 • Public • Published

    Kinesis Logo

    Description

    An effficient Nest.js Kinesis Producer based on Kevin Deng's blog piece

    Installation

    $ npm install nest-kinesis-producer

    Adding the Global Module

    Add the Kinesis Producer to your App Module imports. It will register globally.

    Syncronously:

    import { AppService } from './app.service';
    import { Module } from '@nestjs/common';
    
    @Module({
      imports: [KinesisProducerModule.forRoot(new Kinesis())],
      providers: [AppService],
    })
    export class AppModule {}

    Asyncronously:

    import { AppService } from './app.service';
    import { Module } from '@nestjs/common';
    import { ConfigModule, ConfigService } from '@nestjs/config';
    
    @Module({
      imports: [
          KinesisProducerModule.forRootAsync({
            useFactory: (cfg: ConfigService) => new Kinesis({credentials: cfg.getCreds()}),
            inject: [ConfigService],
            imports: [ConfigModule],
          }),
        ),
      ],
      providers: [AppService],
    })
    export class AppModule {}

    Use the Publisher

    import { hash } from 'crypto';
    import { RetryingBatchKinesisPublisher } from "nest-kinesis-producer";
    
    
    export class AppService {
      constructor(private readonly kinesisPublisher: RetryingBatchKinesisPublisher){}
    
      public async sendToKinesis(messages: string[]): Promise<void> {
        const events = messages.map((x) => {
          return {
            PartitionKey: this.getPartitionKey(x),
            Data: x
          };
        });
        await this.kinesisPublisher.putRecords('fakeStreamName', events);
      }
    
      public getPartitionKey(mesage: string): string {
        ...
      }
    }

    Support

    Pull requests are welcome. Please remember that commits must be made using Angular conventional-changelog

    Stay in touch

    License

    Nest-Kinesis-Producer is MIT licensed.

    Install

    npm i nest-kinesis-producer

    DownloadsWeekly Downloads

    1

    Version

    2.4.0

    License

    MIT

    Unpacked Size

    37.6 kB

    Total Files

    28

    Last publish

    Collaborators

    • avatar