@tc-libs/rmq
v3.9.0
Published
Helper NestJS per RabbitMQ. Il package copre due esigenze:
Readme
@tc-libs/rmq
Helper NestJS per RabbitMQ. Il package copre due esigenze:
- registrare client RMQ tramite
ClientsModule - costruire opzioni server/consumer e fare
ackdei messaggi
Registrazione del client
RmqModule.register('EMAIL', {
url: 'amqp://guest:guest@localhost:5672',
});La queue usata dal client viene normalizzata come RMQ_<QUEUE>_QUEUE.
Versione async:
RmqModule.registerAsync('EMAIL', {
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
url: config.getOrThrow<string>('RMQ_URL'),
}),
});Servizio
RmqService espone:
getOptions(urls, queue, prefetchCount?, noAck?)ack(context)
Esempio consumer:
@MessagePattern('email.send')
async handle(@Ctx() context: RmqContext) {
// processa il messaggio
this.rmqService.ack(context);
}Esempio bootstrap microservice:
app.connectMicroservice(
this.rmqService.getOptions(
['amqp://guest:guest@localhost:5672'],
'RMQ_EMAIL_QUEUE',
10,
),
);Note operative
- Il modulo e
@Global(). ackusa il channel e il messaggio originali esposti daRmqContext.getOptionsimpostapersistent: true.
Sviluppo
nx build rmq
nx test rmq