nestjs-amqp
Microservizi NestJS che si parlano su RabbitMQ, con un gateway HTTP e WebSocket davanti.
A cosa serve
Installazione
npm i @open-rlb/nestjs-amqpEsempio
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 };
}
}Cosa fa
Decoratori e un file YAML
Gateway HTTP e WebSocket
Accessi e permessi
Quando qualcosa va storto
Rotte che si aggiornano da sole
Pronta con un comando
Requisiti
- NestJS 11
- Un server RabbitMQ raggiungibile
- Nel progetto anche @nestjs/config, @nestjs/axios e js-yaml; @nestjs/platform-ws se si usa il gateway
- Per i moduli ACL e gateway-admin, un database e una cache a scelta, collegati dall'applicazione (gli esempi usano MongoDB o la memoria)