{"id":25803163,"url":"https://github.com/flocasts/nestjs-sqs-microservice","last_synced_at":"2026-06-09T13:31:08.208Z","repository":{"id":275859021,"uuid":"927419842","full_name":"flocasts/nestjs-sqs-microservice","owner":"flocasts","description":"A NestJS Microservice Strategy for SQS","archived":false,"fork":false,"pushed_at":"2025-02-05T06:58:12.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-24T00:28:54.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flocasts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T23:24:23.000Z","updated_at":"2025-02-05T06:58:15.000Z","dependencies_parsed_at":"2025-02-05T00:35:18.690Z","dependency_job_id":null,"html_url":"https://github.com/flocasts/nestjs-sqs-microservice","commit_stats":null,"previous_names":["flocasts/nestjs-sqs-microservice"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/flocasts/nestjs-sqs-microservice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flocasts%2Fnestjs-sqs-microservice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flocasts%2Fnestjs-sqs-microservice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flocasts%2Fnestjs-sqs-microservice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flocasts%2Fnestjs-sqs-microservice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flocasts","download_url":"https://codeload.github.com/flocasts/nestjs-sqs-microservice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flocasts%2Fnestjs-sqs-microservice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34110010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T17:44:22.284Z","updated_at":"2026-06-09T13:31:08.192Z","avatar_url":"https://github.com/flocasts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS SQS Microservice\n\nThis is a fully featured NestJS microservice wrapper for [sqs-consumer](https://www.npmjs.com/package/sqs-consumer),\nleveraging the wonderful feature set of the NestJS Microservice ecosystem. This means you get a seamless, controller\nbased experience for interacting with SQS queues!\n\n## Features\n\n### Decorators\n\n| Name                      | Type               | Description                                         | Options                                                                               | Batch Compatible   |\n| ------------------------- | ------------------ | --------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------ |\n| **@SqsMessageHandler**    | Method Decorator   | Marks a Controller method as an SQS Message Handler | [ConsumerOptions](https://bbc.github.io/sqs-consumer/interfaces/ConsumerOptions.html) | :white_check_mark: |\n| **@SqsMessageBody**       | Property Decorator | Extracts the message body from the SQS message      | Body key (optional)                                                                   | :x:                |\n| **@SqsMessageId**         | Property Decorator | Extracts the message ID from the SQS message        |                                                                                       | :x:                |\n| **@SqsAttributes**        | Property Decorator | Extracts attributes from the SQS message            | Attribute Key (optional)                                                              | :x:                |\n| **@SqsMessageAttributes** | Property Decorator | Extracts message attributes from the SQS message    | Message Attribute Key (optional)                                                      | :x:                |\n| **@SqsBatchMessages**     | Property Decorator | Extracts messages from an SQS Batch message         |                                                                                       | :white_check_mark: |\n\n## Getting Started\n\n### Setting up the Microservice\n\n#### Hybrid Applications\n\nIn most cases you'll end up going with a hybrid application, meaning you'll use both HTTP and Microservice handlers, here's how you do that:\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { TestModule } from './test.module.js';\nimport { AwsSQSServer } from '../index.js';\n\nasync function bootstrap() {\n    const app = await NestFactory.create(TestModule);\n    app.connectMicroservice({\n        strategy: new AwsSQSServer(),\n    });\n\n    await app.startAllMicroservices();\n    await app.listen(3000);\n}\nbootstrap();\n```\n\n[Check here for the full file](./test/test.hybrid-app.ts)\n\n#### Standalone Microservice Applications\n\nSometimes you do just need a microservice though, and here's what that looks like:\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { TestModule } from './test.module.js';\nimport { AwsSQSServer } from '../index.js';\n\nasync function bootstrap() {\n    const app = await NestFactory.createMicroservice(TestModule, {\n        strategy: new AwsSQSServer(),\n    });\n\n    await app.listen();\n}\nbootstrap();\n```\n\n[Check here for the full file](./test/test.app.ts)\n\n### Setting up Controllers\n\nHere's the controller from our tests ([check here for the full thing!](./test/test.sqs-controller.ts)):\n\n```typescript\n@Controller()\nexport class TestSqsController {\n    private readonly logger = new Logger(TestSqsController.name);\n\n    @SqsMessageHandler({\n        queueUrl: process.env.SQS_QUEUE_URL!,\n        attributeNames: ['All'],\n    })\n    public async messageHandler(\n        // This will extract the message body from the SQS message\n        @SqsMessageBody(new ZodValidationPipe(testSchema)) body: TestSchema,\n        // This will extract the message ID from the SQS message\n        @SqsMessageId() messageId: string,\n        // This will extract the attributes  from the SQS message\n        @SqsAttributes() attributes: unknown,\n        @SqsAttributes('SenderId') senderId: unknown,\n        // This will extract the message attributes from the SQS message\n        @SqsMessageAttributes() messageAttributes: unknown,\n    ): Promise\u003cvoid\u003e {\n        this.logger.log({msg: 'A message was received!', messageId, messageAttributes, attributes, body, senderId });\n    }\n```\n\nWe also support the batch syntax, as used by `sqs-consumer`:\n\n```typescript\n@Controller()\nexport class TestSqsController {\n    private readonly logger = new Logger(TestSqsController.name);\n\n    @SqsMessageHandler({\n        queueUrl: process.env.SQS_QUEUE_URL!,\n        batch: true,\n    })\n    public async batchMessageHandler(@SqsBatchMessages() messages: Message[]): Promise\u003cvoid\u003e {\n        this.logger.log({ msg: 'A batch message was received!', messages });\n    }\n}\n```\n\nN.B. Each queue url can only have _one_ message handler, regardless of whether is is batched. After the initial handler is detected, any subsequent handlers will result in an error.\n\n#### Queue Events\n\nIn addition to messages, we also expose other events available from the `sqs-consumer` library,\nhere's an example.\n\n```typescript\n@Controller()\nexport class TestSqsController {\n    private readonly logger = new Logger(TestSqsController.name);\n\n    @SqsMessageHandler({\n        queueUrl: process.env.SQS_QUEUE_URL!,\n        attributeNames: ['All'],\n    })\n    public async messageHandler(): Promise\u003cvoid\u003e {\n        this.logger.log({ msg: 'A message was received!' });\n    }\n\n    @SqsQueueEventHandler({\n        queueUrl: process.env.SQS_QUEUE_URL!,\n        event: 'error',\n    })\n    public async eventHandler([error, message]: Events['error']): Promise\u003cvoid\u003e {\n        this.logger.log({ msg: 'An event was received!', error, message });\n    }\n}\n```\n\nN.B. Only one handler for each event can be applied _per queue_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflocasts%2Fnestjs-sqs-microservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflocasts%2Fnestjs-sqs-microservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflocasts%2Fnestjs-sqs-microservice/lists"}