@golevelup/nestjs is a really powerful library when using RabbitMQ with NestJS.
It's a way more advanced library compared to @nestjs/microservices for RabbitMQ integration.
Currently it's not compatible with nestjs-i18n because it uses an ExecutionContext type rmq which is not handled by nestjs-i18n.
This PR aims to use the ConsumeMessage as container for the i18nContext, to enable creating custom lang resolvers for RabbitMQ consumers:
import { ExecutionContext } from '@nestjs/common';
import { I18nResolver } from 'nestjs-i18n';
export class RabbitMqHeaderResolver implements I18nResolver {
resolve(context: ExecutionContext): string | undefined {
if (context.getType<string>() === 'rmq') {
const consumeMessage = context.getArgs()[1] as ConsumeMessage;
return message.properties.headers['x-lang'];
}
return undefined;
}
}
It's not so simple to test this new feature as it requires to setup a RabbitMQ instance in tests.
But it's still possible to do something similar to this setup:
coverage: 90.764% (-0.2%) from 90.925%
when pulling 85c491f2c0b822943bf654c21de77f19cb2c4282 on lucas-gregoire:feat/rmq-context
into a861a2f688266e500e0bec07f65831348cf4ea74 on toonvanstrijp:main.
Description
@golevelup/nestjs is a really powerful library when using RabbitMQ with NestJS. It's a way more advanced library compared to
@nestjs/microservices
for RabbitMQ integration.Currently it's not compatible with
nestjs-i18n
because it uses anExecutionContext
typermq
which is not handled bynestjs-i18n
. This PR aims to use theConsumeMessage
as container for thei18nContext
, to enable creating custom lang resolvers for RabbitMQ consumers:It's not so simple to test this new feature as it requires to setup a RabbitMQ instance in tests. But it's still possible to do something similar to this setup: