From d637bd4f9617b2dca55c9a16f5cf5e1dfecef49f Mon Sep 17 00:00:00 2001 From: Deniks Date: Sat, 27 Jan 2024 16:12:38 +0000 Subject: [PATCH] feat(microservices): add type for rmq connection options change socketOptions.connectionOptions type from any to amqp-manager's AmqpConnectionOptions which allows to specify not only mTLS but also External auth Closes https://github.com/nestjs/nest/issues/13071 --- packages/microservices/client/client-rmq.ts | 6 +++--- packages/microservices/external/rmq-url.interface.ts | 4 +++- packages/microservices/server/server-rmq.ts | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/microservices/client/client-rmq.ts b/packages/microservices/client/client-rmq.ts index 05844b4889c..81410caedbb 100644 --- a/packages/microservices/client/client-rmq.ts +++ b/packages/microservices/client/client-rmq.ts @@ -44,7 +44,7 @@ type ChannelWrapper = any; type ConsumeMessage = any; type AmqpConnectionManager = any; -let rqmPackage: any = {}; +let rmqPackage: any = {}; const REPLY_QUEUE = 'amq.rabbitmq.reply-to'; @@ -81,7 +81,7 @@ export class ClientRMQ extends ClientProxy { this.getOptionsProp(this.options, 'noAssert') || RQM_DEFAULT_NO_ASSERT; loadPackage('amqplib', ClientRMQ.name, () => require('amqplib')); - rqmPackage = loadPackage('amqp-connection-manager', ClientRMQ.name, () => + rmqPackage = loadPackage('amqp-connection-manager', ClientRMQ.name, () => require('amqp-connection-manager'), ); @@ -133,7 +133,7 @@ export class ClientRMQ extends ClientProxy { public createClient(): AmqpConnectionManager { const socketOptions = this.getOptionsProp(this.options, 'socketOptions'); - return rqmPackage.connect(this.urls, { + return rmqPackage.connect(this.urls, { connectionOptions: socketOptions, }); } diff --git a/packages/microservices/external/rmq-url.interface.ts b/packages/microservices/external/rmq-url.interface.ts index d7abd16046b..ac9fdf19cbd 100644 --- a/packages/microservices/external/rmq-url.interface.ts +++ b/packages/microservices/external/rmq-url.interface.ts @@ -1,3 +1,5 @@ +import { AmqpConnectionManager } from 'amqp-connection-manager'; + /** * @publicApi */ @@ -25,7 +27,7 @@ export interface AmqpConnectionManagerSocketOptions { reconnectTimeInSeconds?: number; heartbeatIntervalInSeconds?: number; findServers?: () => string | string[]; - connectionOptions?: any; + connectionOptions?: AmqpConnectionManager['connectionOptions']; clientProperties?: ClientProperties; [key: string]: any; } diff --git a/packages/microservices/server/server-rmq.ts b/packages/microservices/server/server-rmq.ts index 3b2f52a3c61..3d2c178f108 100644 --- a/packages/microservices/server/server-rmq.ts +++ b/packages/microservices/server/server-rmq.ts @@ -31,7 +31,7 @@ import { import { RmqRecordSerializer } from '../serializers/rmq-record.serializer'; import { Server } from './server'; -let rqmPackage: any = {}; +let rmqPackage: any = {}; const INFINITE_CONNECTION_ATTEMPTS = -1; @@ -67,7 +67,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy { this.getOptionsProp(this.options, 'noAssert') || RQM_DEFAULT_NO_ASSERT; this.loadPackage('amqplib', ServerRMQ.name, () => require('amqplib')); - rqmPackage = this.loadPackage( + rmqPackage = this.loadPackage( 'amqp-connection-manager', ServerRMQ.name, () => require('amqp-connection-manager'), @@ -136,7 +136,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy { public createClient(): T { const socketOptions = this.getOptionsProp(this.options, 'socketOptions'); - return rqmPackage.connect(this.urls, { + return rmqPackage.connect(this.urls, { connectionOptions: socketOptions, heartbeatIntervalInSeconds: socketOptions?.heartbeatIntervalInSeconds, reconnectTimeInSeconds: socketOptions?.reconnectTimeInSeconds,