@apinecka/amqp
v1.0.1
Published
NestJS module for AMQP/RabbitMQ: declarative exchange/queue/binding schemas, decorator-based consumers, batch consumers, and publish helpers on top of amqp-connection-manager.
Maintainers
Readme
@apinecka/amqp
NestJS module for AMQP/RabbitMQ built on top of
amqp-connection-manager: declarative
exchange/queue/binding schemas, decorator-based consumers, batch consumers, and a small
publish helper.
Install
npm install @apinecka/amqp amqp-connection-manager amqplib @nestjs/common @nestjs/coreUsage
import { AmqpModule, AmqpSchema } from '@apinecka/amqp'
const schema = AmqpSchema.create()
.addQueue({ name: 'logs.publish', prefetch: 100 })
@Module({
imports: [
AmqpModule.forRoot({
urls: ['amqp://user:pass@host/vhost'],
schema,
}),
],
})
export class AppModule {}Consume a queue with a decorator on any provider/controller method:
import { AmqpConsumer } from '@apinecka/amqp'
@AmqpConsumer(schema.queues['logs.publish'])
async handle(data: LogEntry) {
// ...
}See src/amqp.decorators.ts for the full set of decorators (single-message and batch
consumers) and src/amqp.schema.ts for building exchange/queue/binding schemas.
Peer dependencies
@nestjs/commonand@nestjs/core— the module and decorators are NestJS-specific.amqp-connection-manager— connection/channel management with auto-reconnect.amqplib— required transitively byamqp-connection-manager.
License
MIT
