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-extension
or
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
messagingRoutingKey
header to match your NestJS handler:
@MessageHandler('my_app_command.create_user') // routing key to use in SQS message attributes
Last updated