Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add compatibility with @golevelup/rabbitmq #595

Merged
merged 1 commit into from
Nov 4, 2023

Conversation

lucas-gregoire
Copy link
Contributor

@lucas-gregoire lucas-gregoire commented Nov 3, 2023

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 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:

@coveralls
Copy link

Coverage Status

coverage: 90.764% (-0.2%) from 90.925%
when pulling 85c491f on lucas-gregoire:feat/rmq-context
into a861a2f on toonvanstrijp:main.

@rubiin rubiin merged commit 0774e23 into toonvanstrijp:main Nov 4, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants