Skip to content

Commit 7b8d6df

Browse files
committed
fix - [RabbitMQ Microservice] "PRECONDITION_FAILED - reply consumer already set" nestjs#3138
1 parent cc5c749 commit 7b8d6df

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/microservices/client/client-rmq.ts

Lines changed: 9 additions & 5 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$)
@@ -83,11 +84,6 @@ export class ClientRMQ extends ClientProxy {
8384
)
8485
.toPromise();
8586

86-
this.client.on(DISCONNECT_EVENT, (err)=> {
87-
this.close();
88-
this.client = null;
89-
});
90-
9187
return this.connection;
9288
}
9389

@@ -140,6 +136,14 @@ export class ClientRMQ extends ClientProxy {
140136
client.addListener(ERROR_EVENT, (err: any) => this.logger.error(err));
141137
}
142138

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+
143147
public handleMessage(
144148
packet: unknown,
145149
callback: (packet: WritePacket) => any,

0 commit comments

Comments
 (0)