Skip to content

Commit daa98b2

Browse files
committed
๐Ÿ› fix: connection ์ค‘๋ณต ์ƒ์„ฑ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ Promise ์บ์‹ฑ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
1 parent e085f28 commit daa98b2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

โ€Žfeed-crawler/src/common/rabbitmq.manager.tsโ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as amqp from 'amqplib';
66
export 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

0 commit comments

Comments
ย (0)