/nest-kinesis-producer

A TypeScript port for Efficient Kinesis Producing for Interpreted code in Lambda.

Primary LanguageTypeScriptMIT LicenseMIT

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.

import { Module } from '@nestjs/common';
import { AppService } from './app.service';

@Module({
  imports: [KinesisProducerModule.forRoot(new Kinesis())],
  providers: [AppService],
})
export class AppModule {}

Use the Publisher

import { hash } from 'crypto';
export class AppService {
  constructor(private readonly kinesisPublisher: RetryingBatchKinesisPublisher){}

  public async sendToKinesis(messages: string[]): Promise<void> {
    const events = messages.map(x => new KinesisEvent(this.getPartitionKey(x), 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.