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(microservices): add type for rmq connection options #13105

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/microservices/client/client-rmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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'),
);

Expand Down Expand Up @@ -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,
});
}
Expand Down
25 changes: 24 additions & 1 deletion packages/microservices/external/rmq-url.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ConnectionOptions } from 'tls';
import { TcpSocketConnectOpts } from 'net';

/**
* @publicApi
*/
Expand All @@ -18,14 +21,34 @@ interface ClientProperties {
[key: string]: any;
}

type AmqpConnectionOptions = (ConnectionOptions | TcpSocketConnectOpts) & {
noDelay?: boolean;
timeout?: number;
keepAlive?: boolean;
keepAliveDelay?: number;
clientProperties?: any;
credentials?:
| {
mechanism: string;
username: string;
password: string;
response: () => Buffer;
}
| {
mechanism: string;
response: () => Buffer;
}
| undefined;
};

/**
* @publicApi
*/
export interface AmqpConnectionManagerSocketOptions {
reconnectTimeInSeconds?: number;
heartbeatIntervalInSeconds?: number;
findServers?: () => string | string[];
connectionOptions?: any;
connectionOptions?: AmqpConnectionOptions;
clientProperties?: ClientProperties;
Copy link
Contributor Author

@Deniks Deniks Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit wierd that clientProperties in original amqp manager is inside connectionOptions .
I suspect interfaces were not updated when amqp-connection-manager version got changed?

[key: string]: any;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/microservices/server/server-rmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -136,7 +136,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {

public createClient<T = any>(): 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,
Expand Down