File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -52,3 +52,6 @@ export const MQTT_WILDCARD_ALL = '#';
5252export const ECONNREFUSED = 'ECONNREFUSED' ;
5353export const CONN_ERR = 'CONN_ERR' ;
5454export const EADDRINUSE = 'EADDRINUSE' ;
55+
56+ export const CONNECTION_FAILED_MESSAGE =
57+ 'Connection to transport failed. Trying to reconnect...' ;
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ import {
55} from '@nestjs/common/utils/shared.utils' ;
66import {
77 CONNECT_EVENT ,
8- DISCONNECTED_RMQ_MESSAGE ,
8+ CONNECT_FAILED_EVENT ,
9+ CONNECTION_FAILED_MESSAGE ,
910 DISCONNECT_EVENT ,
11+ DISCONNECTED_RMQ_MESSAGE ,
1012 NO_MESSAGE_HANDLER ,
1113 RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT ,
1214 RQM_DEFAULT_NOACK ,
@@ -95,6 +97,10 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
9597 this . logger . error ( DISCONNECTED_RMQ_MESSAGE ) ;
9698 this . logger . error ( err ) ;
9799 } ) ;
100+ this . server . on ( CONNECT_FAILED_EVENT , ( err : any ) => {
101+ this . logger . error ( CONNECTION_FAILED_MESSAGE ) ;
102+ this . logger . error ( err ) ;
103+ } ) ;
98104 }
99105
100106 public createClient < T = any > ( ) : T {
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ describe('ServerRMQ', () => {
5252 server . listen ( callbackSpy ) ;
5353 expect ( onStub . getCall ( 1 ) . args [ 0 ] ) . to . be . equal ( 'disconnect' ) ;
5454 } ) ;
55+ it ( 'should bind "connectFailed" event to handler' , ( ) => {
56+ server . listen ( callbackSpy ) ;
57+ expect ( onStub . getCall ( 2 ) . args [ 0 ] ) . to . be . equal ( 'connectFailed' ) ;
58+ } ) ;
5559 describe ( 'when "start" throws an exception' , ( ) => {
5660 it ( 'should call callback with a thrown error as an argument' , ( ) => {
5761 const error = new Error ( 'random error' ) ;
You can’t perform that action at this time.
0 commit comments