@autofleet/rabbit 3.2.26-beta.200 → 3.2.26-beta.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -9
- package/dist/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +15 -9
- package/src/lib/types.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -132,6 +132,7 @@ class RabbitMq {
|
|
|
132
132
|
creatingConnection: false,
|
|
133
133
|
connectionCreatedEventName: 'publishConnectionCreated',
|
|
134
134
|
connectionFailedEventName: 'publishConnectionFailed',
|
|
135
|
+
doesChannelInitialize: false,
|
|
135
136
|
},
|
|
136
137
|
};
|
|
137
138
|
this.exchanges = {};
|
|
@@ -245,7 +246,7 @@ class RabbitMq {
|
|
|
245
246
|
if (!connection) {
|
|
246
247
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
247
248
|
}
|
|
248
|
-
const channel = connection.createChannel({ ...options });
|
|
249
|
+
const channel = connection.createChannel({ ...options, confirm: false });
|
|
249
250
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
250
251
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
|
251
252
|
onClose?.(args);
|
|
@@ -275,6 +276,7 @@ class RabbitMq {
|
|
|
275
276
|
});
|
|
276
277
|
if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
|
|
277
278
|
this.publishChannel = channel;
|
|
279
|
+
this.connectionsMap[connectionPurpose].doesChannelInitialize = true;
|
|
278
280
|
}
|
|
279
281
|
resolve(channel);
|
|
280
282
|
}
|
|
@@ -566,7 +568,16 @@ class RabbitMq {
|
|
|
566
568
|
async isConnected() {
|
|
567
569
|
debug('rabbit: start is connected');
|
|
568
570
|
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
569
|
-
|
|
571
|
+
const { connection, doesChannelInitialize } = connectionData;
|
|
572
|
+
if (connectionPurpose === consts_1.ConnectionPurpose.Consume
|
|
573
|
+
|| (connectionPurpose === consts_1.ConnectionPurpose.Publish
|
|
574
|
+
&& doesChannelInitialize)) {
|
|
575
|
+
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
576
|
+
const isConnected = connection?.isConnected();
|
|
577
|
+
if (!isConnected) {
|
|
578
|
+
logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
570
581
|
const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
|
|
571
582
|
try {
|
|
572
583
|
await Promise.all([
|
|
@@ -579,13 +590,6 @@ class RabbitMq {
|
|
|
579
590
|
return false;
|
|
580
591
|
}
|
|
581
592
|
}
|
|
582
|
-
const { connection } = connectionData;
|
|
583
|
-
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
584
|
-
const isConnected = connection?.isConnected();
|
|
585
|
-
if (!isConnected) {
|
|
586
|
-
logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
593
|
logger_1.default.info('rabbit: isConnected - true');
|
|
590
594
|
return true;
|
|
591
595
|
}));
|
package/dist/lib/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -183,6 +183,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
183
183
|
creatingConnection: false,
|
|
184
184
|
connectionCreatedEventName: 'publishConnectionCreated',
|
|
185
185
|
connectionFailedEventName: 'publishConnectionFailed',
|
|
186
|
+
doesChannelInitialize: false,
|
|
186
187
|
},
|
|
187
188
|
};
|
|
188
189
|
this.exchanges = {};
|
|
@@ -386,7 +387,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
386
387
|
if (!connection) {
|
|
387
388
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
388
389
|
}
|
|
389
|
-
const channel = connection.createChannel({ ...options });
|
|
390
|
+
const channel = connection.createChannel({ ...options, confirm: false });
|
|
390
391
|
once(channel, 'close').then((args) => {
|
|
391
392
|
logger.error(`rabbit: channel ${name} closed`);
|
|
392
393
|
onClose?.(args);
|
|
@@ -417,6 +418,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
417
418
|
});
|
|
418
419
|
if (connectionPurpose === ConnectionPurpose.Publish) {
|
|
419
420
|
this.publishChannel = channel;
|
|
421
|
+
this.connectionsMap[connectionPurpose].doesChannelInitialize = true;
|
|
420
422
|
}
|
|
421
423
|
resolve(channel);
|
|
422
424
|
} catch (e) {
|
|
@@ -761,7 +763,18 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
761
763
|
debug('rabbit: start is connected');
|
|
762
764
|
const isEachConnectionConnected = await Promise.all(
|
|
763
765
|
Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
764
|
-
|
|
766
|
+
const { connection, doesChannelInitialize } = connectionData;
|
|
767
|
+
if (
|
|
768
|
+
connectionPurpose === ConnectionPurpose.Consume
|
|
769
|
+
|| (connectionPurpose === ConnectionPurpose.Publish
|
|
770
|
+
&& doesChannelInitialize
|
|
771
|
+
)) {
|
|
772
|
+
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
773
|
+
const isConnected = connection?.isConnected();
|
|
774
|
+
if (!isConnected) {
|
|
775
|
+
logger.error('rabbit: isConnected - false', { connectionPurpose });
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
765
778
|
const channel: any = await this.assertChannel({ connectionPurpose: connectionPurpose as ConnectionPurpose });
|
|
766
779
|
try {
|
|
767
780
|
await Promise.all([
|
|
@@ -773,13 +786,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
773
786
|
return false;
|
|
774
787
|
}
|
|
775
788
|
}
|
|
776
|
-
const { connection } = connectionData;
|
|
777
|
-
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
778
|
-
const isConnected = connection?.isConnected();
|
|
779
|
-
if (!isConnected) {
|
|
780
|
-
logger.error('rabbit: isConnected - false', { connectionPurpose });
|
|
781
|
-
return false;
|
|
782
|
-
}
|
|
783
789
|
logger.info('rabbit: isConnected - true');
|
|
784
790
|
return true;
|
|
785
791
|
}),
|