@@ -5,6 +5,7 @@ import { EventEmitter } from 'events';
55import { fromEvent , merge , Observable } from 'rxjs' ;
66import { first , map , share , switchMap } from 'rxjs/operators' ;
77import {
8+ DISCONNECTED_RMQ_MESSAGE ,
89 DISCONNECT_EVENT ,
910 ERROR_EVENT ,
1011 RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT ,
@@ -52,6 +53,8 @@ export class ClientRMQ extends ClientProxy {
5253 public close ( ) : void {
5354 this . channel && this . channel . close ( ) ;
5455 this . client && this . client . close ( ) ;
56+ this . channel = null ;
57+ this . client = null ;
5558 }
5659
5760 public consumeChannel ( ) {
@@ -74,6 +77,7 @@ export class ClientRMQ extends ClientProxy {
7477 }
7578 this . client = this . createClient ( ) ;
7679 this . handleError ( this . client ) ;
80+ this . handleDisconnectError ( this . client ) ;
7781
7882 const connect$ = this . connect$ ( this . client ) ;
7983 this . connection = this . mergeDisconnectEvent ( this . client , connect$ )
@@ -82,6 +86,7 @@ export class ClientRMQ extends ClientProxy {
8286 share ( ) ,
8387 )
8488 . toPromise ( ) ;
89+
8590 return this . connection ;
8691 }
8792
@@ -134,6 +139,15 @@ export class ClientRMQ extends ClientProxy {
134139 client . addListener ( ERROR_EVENT , ( err : any ) => this . logger . error ( err ) ) ;
135140 }
136141
142+ public handleDisconnectError ( client : any ) : void {
143+ client . addListener ( DISCONNECT_EVENT , ( err : any ) => {
144+ this . logger . error ( DISCONNECTED_RMQ_MESSAGE ) ;
145+ this . logger . error ( err ) ;
146+
147+ this . close ( ) ;
148+ } ) ;
149+ }
150+
137151 public handleMessage (
138152 packet : unknown ,
139153 callback : ( packet : WritePacket ) => any ,
0 commit comments