Skip to content

Commit 279f6fa

Browse files
Merge pull request #9751 from delucca-workspaces/fix/server-transport-connection-hanging
fix(microservices): adds feedback message when RabbitMQ server connection hangs
2 parents 52cf0b7 + c9f5f01 commit 279f6fa

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/microservices/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ export const MQTT_WILDCARD_ALL = '#';
5252
export const ECONNREFUSED = 'ECONNREFUSED';
5353
export const CONN_ERR = 'CONN_ERR';
5454
export const EADDRINUSE = 'EADDRINUSE';
55+
56+
export const CONNECTION_FAILED_MESSAGE =
57+
'Connection to transport failed. Trying to reconnect...';

packages/microservices/server/server-rmq.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
} from '@nestjs/common/utils/shared.utils';
66
import {
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 {

packages/microservices/test/server/server-rmq.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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');

0 commit comments

Comments
 (0)