npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nestjstools/messaging-amazon-sqs-extension

v1.5.1

Published

Extension to handle messages and dispatch them over Amazon SQS

Readme

@nestjstools/messaging-amazon-sqs-extension

A NestJS library for managing asynchronous and synchronous messages with support for buses, handlers, channels, and consumers. This library simplifies building scalable and decoupled applications by facilitating robust message handling pipelines while ensuring flexibility and reliability.


Documentation

https://nestjstools.gitbook.io/nestjstools-messaging-docs


Installation

npm install @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension 

or

yarn add @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension

AmazonSQS Integration: Messaging Configuration Example


import { Module } from '@nestjs/common';
import { MessagingModule } from '@nestjstools/messaging';
import { SendMessageHandler } from './handlers/send-message.handler';
import { AmazonSqsChannelConfig, MessagingAmazonSqsExtensionModule } from '@nestjstools/messaging-amazon-sqs-extension';

@Module({
  imports: [
    MessagingAmazonSqsExtensionModule, // Importing the SQS extension module
    MessagingModule.forRoot({
      buses: [
        {
          name: 'message.bus',
          channels: ['sqs-channel'],
        },
      ],
      channels: [
        new AmazonSqsChannelConfig({
          name: 'sqs-channel',
          enableConsumer: true, // Enable if you want to consume messages
          region: 'us-east-1',
          queueUrl: 'http://localhost:9324/queue/test_queue', // ElasticMQ for local development
          autoCreate: true, // Auto-create queue if it doesn't exist
          credentials: { // Optional credentials for SQS
            accessKeyId: 'x',
            secretAccessKey: 'x',
          },
          maxNumberOfMessages: 3, // optional
          visibilityTimeout: 10, // optional 
          waitTimeSeconds: 5, // Every 5 seconds consumer will pull 3 messages from queue - optional,
          deadLetterQueue: false,
        }),
      ],
      debug: true, // Optional: Enable debugging for Messaging operations
    }),
  ],
})
export class AppModule {}

Dispatch messages via bus (example)

import { Controller, Get } from '@nestjs/common';
import { CreateUser } from './application/command/create-user';
import { IMessageBus, MessageBus, RoutingMessage } from '@nestjstools/messaging';

@Controller()
export class AppController {
  constructor(
    @MessageBus('message.bus') private sqsMessageBus: IMessageBus,
  ) {}

  @Get('/sqs')
  createUser(): string {
    this.sqsMessageBus.dispatch(new RoutingMessage(new CreateUser('John FROM SQS'), 'my_app_command.create_user'));

    return 'Message sent';
  }
}

Handler for your message

import { CreateUser } from '../create-user';
import { IMessageBus, IMessageHandler, MessageBus, MessageHandler, RoutingMessage, DenormalizeMessage } from '@nestjstools/messaging';

@MessageHandler('my_app_command.create_user')
export class CreateUserHandler implements IMessageHandler<CreateUser>{

  handle(message: CreateUser): Promise<void> {
    console.log(message);
    // TODO Logic there
  }
}

📨 Communicating Beyond a NestJS Application (Cross-Language Messaging)

To enable communication with a Handler from services written in other languages, follow these steps:

  1. Publish a Message to the queue

  2. Include the Routing Key Header Your message must include a header attribute named messagingRoutingKey. The value should correspond to the routing key defined in your NestJS message handler:

    @MessageHandler('my_app_command.create_user') // <-- Use this value as the routing key
  3. You're Done! Once the message is published with the correct routing key, it will be automatically routed to the appropriate handler within the NestJS application.


🏷️ Sending Custom SQS Message Attributes

In addition to the required messagingRoutingKey header, you can include custom attributes in your SQS messages to enrich the message with metadata such as request IDs, user types, or priority levels.

Example: Sending a Message with Attributes

const exampleAttributes = {
  requestId: {
    DataType: "String",
    StringValue: "req-" + Math.random().toString(36).substring(2, 10),
  },
  timestamp: {
    DataType: "Number",
    StringValue: Date.now().toString(),
  },
  userType: {
    DataType: "String",
    StringValue: "admin",
  },
  priority: {
    DataType: "Number",
    StringValue: "1",
  },
};

this.sqsMessageBus.dispatch(
  new RoutingMessage(
    new CreateUser('John FROM Sqs'),
    'my_app_command.create_user',
    new AmazonSqsMessageOptions(exampleAttributes)
  )
);

⚠️ Don't forget that messagingRoutingKey must still be present — it's used to route the message to the correct handler.


Key Features:

  • Amazon SQS Integration: Easily send and receive messages with Amazon SQS.

  • Local Development Support: Works with ElasticMQ for local development and testing.

  • Automatic Queue Creation: Automatically create queues if they don’t exist (when autoCreate: true).


Configuration options

AmazonSqsChannel

AmazonSqsChannelConfig

| Property | Description | Default Value | |---------------------------|---------------------------------------------------------------------------------------------------------------------------------------|-------------------| | name | The name of the Amazon SQS channel (e.g., 'message.bus'). | | | region | The AWS region for the SQS queue (e.g., 'us-east-1'). | | | queueUrl | The URL of the SQS queue (e.g., 'http://localhost:9324/queue/test_queue'). | | | credentials | AWS credentials for SQS (optional). | | | enableConsumer | Whether to enable message consumption (i.e., processing received messages). | true | | autoCreate | Automatically create the queue if it doesn’t exist. | true | | maxNumberOfMessages | The maximum number of messages to retrieve from the queue in one request. | 1 | | visibilityTimeout | The time in seconds that the message will remain invisible to other consumers after being fetched. | 20 | | waitTimeSeconds | The amount of time (in seconds) for long polling. The consumer will wait up to this time for messages. | 10 | | deadLetterQueue | When set to true, a dead-letter queue (DLQ) is automatically created. The DLQ name follows the pattern: <queue_name>_dead_letter. | false |

Real world working example with RabbitMQ & Redis - but might be helpful to understand how it works

https://github.com/nestjstools/messaging-rabbitmq-example