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

@nestjs/microservices: RabbitMQ connection options not passed to amqp-connection-manager #13429

Closed
4 of 15 tasks
JonathanMbt opened this issue Apr 13, 2024 · 2 comments · Fixed by #13430
Closed
4 of 15 tasks
Labels
needs triage This issue has not been looked into

Comments

@JonathanMbt
Copy link
Contributor

JonathanMbt commented Apr 13, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I have a RabbitMQ node configured with mtls authentication. The problems occurs when I create a nest microservice.
I saw that RabbitMQ connection options were introduced recently (#13071) but are wrongly typed (it's more that the option is not correctly passed).
When you look at the type (https://github.com/nestjs/nest/pull/13105/files#diff-c0aee1a2515f55f6e0244d04cb7c8af79cdd192434a4ea6648fef2c8a0b1d3fdR51) they have to be defined inside Socket Options.
For instance, the following won't work, even if the type is define as this:

  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AppModule,
    {
      transport: Transport.RMQ,
      options: {
        urls: [
          `amqps://${localConfig.rabbitmq.host}:${localConfig.rabbitmq.port}${localConfig.rabbitmq.vhost}`,
        ],
        queue: localConfig.rabbitmq.queue,
        queueOptions: {
          durable: true,
          exclusive: true,
        },
        socketOptions: {
          connectionOptions: {
            cert: readFileSync(
              join(__dirname, '../', localConfig.rabbitmq.certs.client),
            ),
            key: readFileSync(
              join(__dirname, '../', localConfig.rabbitmq.certs.key),
            ),
            passphrase: '',
            ca: [
              readFileSync(
                join(__dirname, '../', localConfig.rabbitmq.certs.ca),
              ),
            ],
            credentials: credentials.external(),
          },
        },
      },
    },
  );

  await app.listen();
}
bootstrap();

Therefore, we can see there (https://github.com/nestjs/nest/pull/13105/files#diff-be75f6c9c2c9a1228b67565a1a57063e16dceb983af8ee57fefb1bbeb2168dc7R136) that the socketOption object is passed into connectionOptions to amqp-connection-manager. It should be passed directly as second argument and not passed into connectionOptions, as socketOptions is already what the amqp-connection-manager is expecting as second argument ! As so, the connection is not configured...
We have the same issue at that point: https://github.com/nestjs/nest/pull/13105/files#diff-93437b04ed0526d1c6af30ba24b8828f140177bfb366ae6dd1dd17e8ed58cf88R139

I hope that I made myself clear.

Minimum reproduction code

https://github.com/JonathanMbt/nestjs-rabbitmq-connection-options-fail

Steps to reproduce

No response

Expected behavior

SocketOptions should not be passed down to connectionOptions, and only the connectionOptions should be passed. So that the Rabbitmq connection options would be taken into account and would permit us to use the nest/microservices with RabbitMQ when using tls authentication.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.7

Packages versions

[System Information]
OS Version     : Linux 6.1
NodeJS Version : v18.13.0
NPM Version    : 8.19.3

[Nest CLI]
Nest CLI Version : 10.1.12

[Nest Platform Information]
microservices version : 10.3.7
schematics version    : 10.0.2
testing version       : 10.1.3
common version        : 10.3.7
config version        : 3.2.2
core version          : 10.3.7
jwt version           : 10.2.0
cli version           : 10.1.12

Node.js version

18.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@JonathanMbt
Copy link
Contributor Author

PR: #13430

@kamilmysliwiec
Copy link
Member

Let's track this here #13430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants