{"id":47267806,"url":"https://github.com/mkfyi/nestjs-rmq","last_synced_at":"2026-03-15T07:18:34.002Z","repository":{"id":169579723,"uuid":"640491273","full_name":"mkfyi/nestjs-rmq","owner":"mkfyi","description":"A decent NestJS module for a more advanced communication between microservices using RabbitMQ.","archived":false,"fork":false,"pushed_at":"2024-10-19T10:54:24.000Z","size":669,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-04T18:40:47.162Z","etag":null,"topics":["amqp","javascript","nest","nest-framework","nodejs","rabbitmq","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkfyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-14T09:13:57.000Z","updated_at":"2025-01-16T16:21:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8e155b5-7ef9-4965-bb5b-a5bc67ca88f1","html_url":"https://github.com/mkfyi/nestjs-rmq","commit_stats":null,"previous_names":["mkilian95/nestjs-rmq","mkfyi/nestjs-rmq"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/mkfyi/nestjs-rmq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkfyi%2Fnestjs-rmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkfyi%2Fnestjs-rmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkfyi%2Fnestjs-rmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkfyi%2Fnestjs-rmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkfyi","download_url":"https://codeload.github.com/mkfyi/nestjs-rmq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkfyi%2Fnestjs-rmq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30537399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-15T07:17:37.589Z","status":"ssl_error","status_checked_at":"2026-03-15T07:17:31.738Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["amqp","javascript","nest","nest-framework","nodejs","rabbitmq","typescript"],"created_at":"2026-03-15T07:18:33.493Z","updated_at":"2026-03-15T07:18:33.980Z","avatar_url":"https://github.com/mkfyi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo-small.svg\" width=\"200\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456\n[circleci-url]: https://circleci.com/gh/nestjs/nest\n\n[nest]: https://nestjs.com\n[rabbitmq]: https://rabbitmq.com\n\n\u003cp align=\"center\"\u003eA decent module for a more advanced communication between microservices.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@mkfyi/nestjs-rmq\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@mkfyi/nestjs-rmq\" alt=\"Package License\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/mkfyi/nestjs-rmq/actions/workflows/publish.yml\"\u003e\u003cimg src=\"https://github.com/mkfyi/nestjs-rmq/actions/workflows/publish.yml/badge.svg\" alt=\"publish\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\nThis package provides a more advanced communication between microservices using the full power of [RabbitMQ][rabbitmq].\n\n## Core library features\n\n- Separate server/client components\n- Allowing multiple connections to one or more RabbitMQ server\n- Just implement the `QueueHandler` interface and mark the class with one of the following decorators\n    1. `@Listener()` - [Basic consumer](https://www.rabbitmq.com/tutorials/tutorial-one-javascript.html), the simplest thing that does *something*\n    2. `@Worker()` - [Work Queues](https://www.rabbitmq.com/tutorials/tutorial-two-javascript.html), distributing tasks among workers\n    3. `@PubSub()` - [Publish/Subscribe](https://www.rabbitmq.com/tutorials/tutorial-three-javascript.html), sending messages to many consumers at once\n    4. `@Routing()` - [Routing](https://www.rabbitmq.com/tutorials/tutorial-four-javascript.html), receiving messages selectively\n    5. `@Topics()` - [Topics](https://www.rabbitmq.com/tutorials/tutorial-five-javascript.html), receiving messages based on a pattern\n    6. `@Rpc()` - [RPC](https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html), Request/reply pattern\n- Optional validation of message content using [class-validator](https://www.npmjs.com/package/class-validator)\n- Lightweight wrapper of the `amqplib` for the [Nest][nest] ecosystem\n\n## Installation\n\n`nest-rmq` must be integrated into the ecosystem of [Nest][nest], so your application **must** require `@nestjs/common` and `@nestjs/core`. You can replace all `npm` commands with the package manager of your choice. So if you would like to use `yarn`, replace `npm` with `yarn`.\n\n```bash\n# from official npm registry\n$ npm i --save @mkfyi/nestjs-rmq\n\n# using yarn\n$ yarn add @mkfyi/nestjs-rmq\n\n# from GitHub package registry\n$ npm i --save --registry=https://npm.pkg.github.com @mkfyi/nestjs-rmq\n\n# from GitHub package registry using yarn\n$ yarn add --registry=https://npm.pkg.github.com @mkfyi/nestjs-rmq\n```\n\nSince `nest-rmq` is built on top of [amqplib](https://www.npmjs.com/package/amqplib) you also need to install the types for it.\n\n```bash\n$ npm install -D @types/amqplib\n```\n\n### Usage\n\nImport the `RabbitMQModule` from `@mkfyi/nestjs-rmq` and call the `forRoot()` method inside the imports of your application module. You can also set a custom `name` for the connection, otherwise `default` will be used.\n\n#### Initialization\n\n```TypeScript\nimport { RabbitMQModule } from '@mkfyi/nestjs-rmq';\n\n@Module({\n  imports: [\n    // ...\n    RabbitMQModule.forRoot({\n      connection: {\n        hostname: '',\n        username: '',\n        password: '',\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nIf you prefer to use environment variables, consider adding the `@nestjs/config` and use `forRootAsync()` method instead.\n\n```TypeScript\n@Module({\n  imports: [\n    // ...\n    RabbitMQModule.forRootAsync({\n      connection: {\n        imports: [ConfigModule],\n        useFactory: (config: ConfigService) =\u003e ({\n          hostname: config.get('AMQP_HOSTNAME'),\n          username: config.get('AMQP_USERNAME'),\n          password: config.get('AMQP_PASSWORD'),\n        }),\n        inject: [ConfigService],\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n##### Multiple connections\n\nYou can also create multiple connections, just pass the object as above into an array and add the `name` property. This `name` is being used for the `QueueHandler` and `QueueAdapter`.\n\n```TypeScript\n@Module({\n  imports: [\n    // ...\n    RabbitMQModule.forRootAsync({\n      connection: [\n        {\n          name: 'default',\n          imports: [ConfigModule],\n          useFactory: (config: ConfigService) =\u003e ({\n            hostname: config.get('AMQP_HOSTNAME'),\n            username: config.get('AMQP_USERNAME'),\n            password: config.get('AMQP_PASSWORD'),\n          }),\n          inject: [ConfigService],\n        },\n        {\n          name: 'stage',\n          imports: [ConfigModule],\n          useFactory: (config: ConfigService) =\u003e ({\n            hostname: config.get('AMQP_STAGE_HOSTNAME'),\n            username: config.get('AMQP_STAGE_USERNAME'),\n            password: config.get('AMQP_STAGE_PASSWORD'),\n          }),\n          inject: [ConfigService],\n        }\n      ],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n##### Adapters (client)\n\nYou have to configure the `adapters` properts in order send messages to the respective queue.\n\n```TypeScript\n@Module({\n  imports: [\n    // ...\n    RabbitMQModule.forRootAsync({\n      connection: {\n        name: 'default',\n        imports: [ConfigModule],\n        useFactory: (config: ConfigService) =\u003e ({\n          hostname: config.get('AMQP_HOSTNAME'),\n          username: config.get('AMQP_USERNAME'),\n          password: config.get('AMQP_PASSWORD'),\n        }),\n        inject: [ConfigService],\n      },\n      adapters: [\n        {\n          name: 'BACKEND_SERVICE',\n          queue: 'example.worker,\n          type: QueueAdapterType.Worker,\n          connection: 'default',\n        },\n      ],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nThe example shown above creates an adapter named `BACKEND_SERVICE` for the `default` connection. The value of the `name` property can be injected as `QueueAdapter` using `@Inject()`. You may want to change to `RpcQueueAdapter` for this type.\n\n```TypeScript\n@Injectable()\nexport class MyService {\n  public constructor(\n    @Inject('BACKEND_SERVICE')\n    private readonly worker: QueueAdapter,\n  ) {}\n\n  public notifyUsernameUpdate(id: string, name: string) {\n    return this.worker.send({ id, name });\n  }\n}\n```\n\n##### Handlers (server)\n\nEvery custom queue handler has to implement the `QueueHandler` interface. As for the adapters, there is a separate interface for RPC based handlers called `RpcQueueHandler`.\n\n```TypeScript\n@Worker({ queue: 'example.worker' })\nexport class ExampleWorkerQueueHandler implements QueueHandler {\n  public async execute(msg: Message): Promise\u003cvoid\u003e {\n    console.log(msg.object());\n  }\n}\n```\n\nDon't forget to add your queue handlers to the application module providers.\n\n```TypeScript\n@Module({\n  imports: [\n    // ...\n    RabbitMQModule.forRootAsync({\n      // ...\n    }),\n  ],\n  providers: [\n    // ...\n    ExampleWorkerQueueHandler,\n  ],\n})\nexport class AppModule {}\n```\n\n## License\n\n[nest-rmq](https://github.com/mkfyi/nestjs-rmq) is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkfyi%2Fnestjs-rmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkfyi%2Fnestjs-rmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkfyi%2Fnestjs-rmq/lists"}