Skip to content

Commit 79dd6d0

Browse files
Merge branch 'buxfix/3138-rabbitMQ-consumer-already-set' of https://github.com/sergey-telpuk/nest into sergey-telpuk-buxfix/3138-rabbitMQ-consumer-already-set
2 parents 013f6f1 + 7b8d6df commit 79dd6d0

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/microservices/client/client-rmq.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class ClientRMQ extends ClientProxy {
7474
}
7575
this.client = this.createClient();
7676
this.handleError(this.client);
77+
this.handleDisconnectError(this.client);
7778

7879
const connect$ = this.connect$(this.client);
7980
this.connection = this.mergeDisconnectEvent(this.client, connect$)
@@ -82,6 +83,7 @@ export class ClientRMQ extends ClientProxy {
8283
share(),
8384
)
8485
.toPromise();
86+
8587
return this.connection;
8688
}
8789

@@ -134,6 +136,14 @@ export class ClientRMQ extends ClientProxy {
134136
client.addListener(ERROR_EVENT, (err: any) => this.logger.error(err));
135137
}
136138

139+
public handleDisconnectError(client: any): void {
140+
client.addListener(DISCONNECT_EVENT, (err: any) => {
141+
this.close();
142+
this.client = null;
143+
return this.logger.error(err);
144+
});
145+
}
146+
137147
public handleMessage(
138148
packet: unknown,
139149
callback: (packet: WritePacket) => any,

packages/microservices/server/server-rmq.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
6969
public async start(callback?: () => void) {
7070
this.server = this.createClient();
7171
this.server.on(CONNECT_EVENT, (_: any) => {
72+
if (this.channel) {
73+
return;
74+
}
7275
this.channel = this.server.createChannel({
7376
json: false,
7477
setup: (channel: any) => this.setupChannel(channel, callback),

0 commit comments

Comments
 (0)