@santaz/nestjs-aws-sqs
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

nestjs-sqs

Installation

$ npm i --save @santaz/nestjs-aws-sqs

Quick Start

Register module

Just register this module:

@Module({
  imports: [
    SqsModule.register({
      consumers: [],
      producers: [],
    }),
  ],
})
class AppModule {}

Decorate methods

You need to decorate methods in your NestJS providers in order to have them be automatically attached as event handlers for incoming SQS messages:

@Injectable()
export class AppMessageHandler {
  @SqsMessageHandler('queueName', /** batch: */ false)
  public async handleMessage(message: AWS.SQS.Message) {
  }
  
  @SqsConsumerEventHandler('queueName', 'processing_error')
  public onProcessingError(error: Error, message: AWS.SQS.Message) {
    // report errors here
  }
}

Produce messages

export class AppService {
  public constructor(
    private readonly sqsService: SqsService,
  ) { }
  
  public async dispatchSomething() {
    await this.sqsService.send('queueName', {
      id: 'id',
      body: { ... },
      groupId: 'groupId',
      deduplicationId: 'deduplicationId',
      messageAttributes: { ... },
      delaySeconds: 0,
    });
  }
}

License

This project is licensed under the terms of the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i @santaz/nestjs-aws-sqs

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

20.8 kB

Total Files

15

Last publish

Collaborators

  • santaz