About this project
nestx-amqp provides an AMQP connection as a NestJS module, using amqp-connection-manager internally. It is published on npm and released under the MIT License.
Features
- Provides an AmqpModule that creates an AmqpConnectionManager asynchronously.
- Provides a globally injectable AMQP connection manager.
- Provides method decorators such as @PublishQueue and @SubscribeQueue for simple usage.
Installation
- yarn add nestx-amqp
Usage
- Register the module asynchronously with AmqpModule.forRootAsync, supplying connection URLs (for example amqp://guest:guest@localhost:5672?heartbeat=60).
- Inject the connection manager using the AMQP_CONNECTION symbol. The README shows an abstract producer that creates a channel with json:true and a setup callback asserting a queue, waits for connection, and sends messages to the queue.
Decorators
- @PublishQueue(queue: string | Queue, options?: amqplib.Options.Publish) is a method decorator for publishing a message to a queue. The decorated method receives content and optional publish options.
- @SubscribeQueue(nameOrQueue: string | Queue, options?: ConsumeQueueOptions) is a method decorator for consuming messages, with simple requeue logic. ConsumeQueueOptions combines prefetch, an optional exceptionQueue, and optional retry settings (maxAttempts).
- @PublishExchange(exchange: string | Exchange, options?: PublishExchangeOptions) publishes to an exchange; the README marks it as not stable and points to unit tests for usage.
- @UseAmqpConnection(name?: string) specifies which named connection to use with @PublishQueue or @SubscribeQueue, recommended when developing npm packages that need a specific named connection.
Interfaces
- Queue: name and optional AssertQueue options.
- Exchange: name, type (direct, fanout, topic, headers), and optional AssertExchange options.
- PublishExchangeOptions: routingKey and optional Publish options.
- RetryOptions: maxAttempts.
- BaseConsumeOptions: prefetch and optional exceptionQueue.
Notes
- The README states that decorator support currently covers only direct queue publish and subscribe.
- Examples require registering and enabling AmqpModule.
- More details are said to be available in the unit test cases, and a CHANGELOG.md is referenced.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.