@santaz/nestjs-aws-sqs
v1.0.2
Published
## Installation
Downloads
6
Readme
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.