nestjs-amqp
NestJS microservices that talk over RabbitMQ, with an HTTP and WebSocket gateway in front.
What it's for
Installation
npm i @open-rlb/nestjs-amqpExample
import { Injectable } from '@nestjs/common';
import { BrokerAction, BrokerParam } from '@open-rlb/nestjs-amqp';
@Injectable()
export class OrdersService {
// (topic, action) = ('orders', 'order.create') — unique across the app
@BrokerAction('orders', 'order.create', 'rpc')
create(
@BrokerParam('header', 'X-GTW-AUTH-USERID') userId: string, // one header
@BrokerParam('body', 'sku') sku: string, // one body field
@BrokerParam('body-full') payload: any, // whole body
@BrokerParam('action') action: string, // the action string
) {
return { ok: true, userId, sku, action };
}
}What it does
Decorators and one YAML file
HTTP and WebSocket gateway
Access and permissions
When something goes wrong
Routes that keep themselves current
Ready with one command
Requirements
- NestJS 11
- A reachable RabbitMQ server
- Also in the project: @nestjs/config, @nestjs/axios and js-yaml; @nestjs/platform-ws if you use the gateway
- For the ACL and gateway-admin modules, a database and cache of your choice, wired in by the application (the samples use MongoDB or memory)