Amazon SQS
π¨ Amazon SQS Channel Integration
This extension enables seamless integration between @nestjstools/messaging and Amazon Simple Queue Service (SQS). It supports both cloud-based and local queue setups (via ElasticMQ) for reliable, scalable, and distributed messaging.
π¦ Installation
npm install @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extensionor
yarn add @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extensionβοΈ Example Configuration
import { Module } from '@nestjs/common';
import { MessagingModule } from '@nestjstools/messaging';
import { MessagingAmazonSQSExtensionModule, AmazonSqsChannelConfig } from '@nestjstools/messaging-amazon-sqs-extension';
import { SendMessageHandler } from './handlers/send-message.handler';
@Module({
imports: [
MessagingAmazonSQSExtensionModule,
MessagingModule.forRoot({
messageHandlers: [SendMessageHandler],
buses: [
{
name: 'sqs-event.bus',
channels: ['sqs-event'],
},
],
channels: [
new AmazonSqsChannelConfig({
name: 'sqs-event',
region: 'us-east-1',
queueUrl: 'http://localhost:9324/queue/test_queue', // ElasticMQ for local use
autoCreate: true,
enableConsumer: true,
credentials: {
accessKeyId: 'x',
secretAccessKey: 'x',
},
maxNumberOfMessages: 3,
visibilityTimeout: 10,
waitTimeSeconds: 5,
}),
],
debug: true,
}),
],
})
export class AppModule {}π οΈ AmazonSqsChannelConfig Properties
name
Name of the SQS channel (e.g., 'sqs-event').
β
region
AWS region for the queue (e.g., 'us-east-1').
β
queueUrl
Full URL of the SQS queue.
β
credentials
Optional AWS credentials (accessKeyId & secretAccessKey).
β
enableConsumer
Whether to enable consuming messages from this queue.
true
autoCreate
Automatically create the queue if it doesn't exist.
true
maxNumberOfMessages
Number of messages to fetch in a single poll.
1
visibilityTimeout
Time (seconds) to hide a message after retrieval.
20
waitTimeSeconds
Duration (seconds) the consumer waits for messages (long polling).
0
π Cross-Language Communication
To integrate with external (non-NestJS) systems:
Publish a message to the SQS queue.
Set the
messagingRoutingKeyheader to match your NestJS handler:
Last updated