@golevelup/nestjs-rabbitmq

Decorator-driven RabbitMQ publish/subscribe and RPC handlers for NestJS applications

Library
npm
v9.0.2
2,736stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity80
Maintenance76
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality78
Innovation76
Learning Curve70

@golevelup/nestjs-rabbitmq is a NestJS module, part of the golevelup/nestjs monorepo, that exposes RabbitMQ messaging as ordinary decorated NestJS service methods instead of hand-rolled amqplib channel code. RabbitMQModule.forRoot() declares exchanges and channels once, after which @RabbitSubscribe and @RabbitRPC decorators turn any provider method into a message consumer — including RPC over RabbitMQ’s Direct Reply-To queue for request/response patterns — while still running through NestJS’s guard/interceptor/filter pipeline. Built on amqp-connection-manager for connection resiliency, it also exposes an AmqpConnection service for publishing messages and an isRabbitContext/RABBIT_CONTEXT_TYPE_KEY mechanism so global HTTP enhancers can distinguish RabbitMQ contexts from HTTP ones.

What You Get

  • RabbitMQModule.forRoot() to declare exchanges, channels, and connection URI in one place, with automatic assertion on startup
  • @RabbitSubscribe decorator to turn any provider method into a queue/routing-key consumer
  • @RabbitRPC decorator implementing request/response messaging over RabbitMQ’s Direct Reply-To queue for low-overhead RPC
  • An injectable AmqpConnection service for publishing messages, plus direct access to the underlying channel/connection when needed
  • Connection resiliency via amqp-connection-manager, with connectionInitOptions: { wait: false } to let the app boot even when RabbitMQ is temporarily unavailable
  • isRabbitContext/RABBIT_CONTEXT_TYPE_KEY helpers so global NestJS interceptors, guards, and filters can distinguish RabbitMQ message contexts from HTTP request contexts

Common Use Cases

  • Building event-driven microservices where NestJS services publish and consume domain events over RabbitMQ exchanges
  • Implementing request/response RPC between services using RabbitMQ’s Direct Reply-To queue instead of a separate synchronous transport
  • Adding resilient message consumers that keep the application bootable and self-healing when the RabbitMQ broker is briefly unreachable
  • Reusing existing NestJS guards, interceptors, and exception filters across both HTTP and message-driven code paths in the same application

Under The Hood

Architecture The rabbitmq package (packages/rabbitmq/src) centers on rabbitmq.module.ts, which wires an internal amqp/connection.ts (wrapping amqp-connection-manager) and amqp/connectionManager.ts into NestJS’s module system, while rabbitmq.decorators.ts registers metadata that a discovery mechanism (shared with the monorepo’s packages/discovery package) scans at bootstrap to find @RabbitSubscribe/@RabbitRPC-annotated provider methods and bind them as consumers on the managed connection.

Tech Stack TypeScript throughout, built with tsc against a shared tsconfig.build.json, depending on amqp-connection-manager and amqplib for the underlying AMQP protocol implementation, tested with Jest-style spec files (amqp.connection.spec.ts, rabbitmq.module.spec.ts) covering both the connection wrapper and module bootstrap, inside an Nx-style monorepo alongside sibling packages for Stripe, Hasura, GraphQL, and webhooks.

Code Quality Dedicated spec files cover connection error handling (amqp.connection.errors.spec.ts) separately from happy-path behavior, decorator metadata and connection management are split into focused files (rabbitmq.decorators.ts, rabbitmq.factory.ts, amqp/connectionManager.ts) rather than one large module, and the package has a steady release cadence (78 releases) reflecting active maintenance rather than a one-off contribution.

API Design The module-level forRoot() configuration plus method-level @RabbitSubscribe/@RabbitRPC decorators follow NestJS’s own established module/decorator conventions, so anyone familiar with NestJS providers can adopt it quickly, though understanding exchange/channel/prefetch configuration and the isRabbitContext escape hatch for global enhancers requires some RabbitMQ-specific background beyond plain NestJS knowledge.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search