File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import * as amqp from 'amqplib';
66export class RabbitMQManager {
77 private connection : ChannelModel | null ;
88 private channel : Channel | null ;
9+ private connectionPromise : Promise < ChannelModel > | null = null ;
910 private channelPromise : Promise < Channel > | null = null ;
1011
1112 constructor ( ) {
@@ -15,15 +16,18 @@ export class RabbitMQManager {
1516
1617 async connect ( ) {
1718 if ( this . connection ) return this . connection ;
19+ if ( this . connectionPromise ) return this . connectionPromise ;
1820
19- this . connection = await amqp . connect ( {
21+ this . connectionPromise = amqp . connect ( {
2022 protocol : 'amqp' ,
2123 hostname : process . env . RABBITMQ_HOST ,
2224 port : Number . parseInt ( process . env . RABBITMQ_PORT ) ,
2325 username : process . env . RABBITMQ_DEFAULT_USER ,
2426 password : process . env . RABBITMQ_DEFAULT_PASS ,
2527 } ) ;
2628
29+ this . connection = await this . connectionPromise ;
30+ this . connectionPromise = null ;
2731 return this . connection ;
2832 }
2933
You canโt perform that action at this time.
0 commit comments