@autofleet/rabbit 3.2.11 → 3.2.13-beta.1
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 +18 -7
- package/package.json +2 -2
- package/src/index.ts +17 -7
package/dist/index.js
CHANGED
|
@@ -217,8 +217,15 @@ class RabbitMq {
|
|
|
217
217
|
}
|
|
218
218
|
async getNewChannel({ name = utils_1.rand().toString(), onClose = null, options = {} } = {}) {
|
|
219
219
|
return new Promise(async (resolve, reject) => {
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
let connection;
|
|
221
|
+
try {
|
|
222
|
+
connection = await this.getConnection();
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
226
|
+
reject(e);
|
|
227
|
+
}
|
|
228
|
+
const channel = connection?.createChannel({
|
|
222
229
|
...options,
|
|
223
230
|
});
|
|
224
231
|
let isResolved = false;
|
|
@@ -323,11 +330,14 @@ class RabbitMq {
|
|
|
323
330
|
return queue;
|
|
324
331
|
}
|
|
325
332
|
saveConsumer(queue, callback, options) {
|
|
326
|
-
this.consumers.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
333
|
+
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
334
|
+
if (!isConsumerExist) {
|
|
335
|
+
this.consumers.push({
|
|
336
|
+
queue,
|
|
337
|
+
callback,
|
|
338
|
+
options,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
331
341
|
}
|
|
332
342
|
async consume(queue, callback, options) {
|
|
333
343
|
await this.consumeFromRabbit(queue, callback, options);
|
|
@@ -438,6 +448,7 @@ class RabbitMq {
|
|
|
438
448
|
RabbitMq.validateName('exchange', exchange);
|
|
439
449
|
RabbitMq.validateName('queue', queue);
|
|
440
450
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
451
|
+
await this.saveConsumer(queue, callback, options);
|
|
441
452
|
const channel = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
|
|
442
453
|
return channel.addSetup(async (c) => {
|
|
443
454
|
const assertExchange = await utils_1.assertExchangeFanout(c, exchange);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.13-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@autofleet/logger": "^1.2.8",
|
|
19
|
-
"@autofleet/zehut": "
|
|
19
|
+
"@autofleet/zehut": "3.0.7",
|
|
20
20
|
"@types/amqplib": "0.8.2",
|
|
21
21
|
"@types/uuid": "^8.3.3",
|
|
22
22
|
"amqp-connection-manager": "4.1.9",
|
package/src/index.ts
CHANGED
|
@@ -350,8 +350,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
350
350
|
|
|
351
351
|
async getNewChannel({ name = rand().toString(), onClose = null, options = {} }: newChannelOpts = {}) {
|
|
352
352
|
return new Promise<ChannelWrapper>(async (resolve, reject) => {
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
let connection!: AmqpConnectionManager;
|
|
354
|
+
try {
|
|
355
|
+
connection = await this.getConnection();
|
|
356
|
+
} catch (e) {
|
|
357
|
+
logger.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
358
|
+
reject(e);
|
|
359
|
+
}
|
|
360
|
+
const channel = connection?.createChannel({
|
|
355
361
|
...options,
|
|
356
362
|
});
|
|
357
363
|
|
|
@@ -464,11 +470,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
464
470
|
}
|
|
465
471
|
|
|
466
472
|
private saveConsumer(queue: string, callback: CallbackFunction, options: ConsumeOptions | undefined) {
|
|
467
|
-
this.consumers.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
473
|
+
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
474
|
+
if (!isConsumerExist) {
|
|
475
|
+
this.consumers.push({
|
|
476
|
+
queue,
|
|
477
|
+
callback,
|
|
478
|
+
options,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
472
481
|
}
|
|
473
482
|
|
|
474
483
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
@@ -601,6 +610,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
601
610
|
RabbitMq.validateName('exchange', exchange);
|
|
602
611
|
RabbitMq.validateName('queue', queue);
|
|
603
612
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
613
|
+
await this.saveConsumer(queue, callback, options);
|
|
604
614
|
const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
|
|
605
615
|
|
|
606
616
|
return channel.addSetup(async (c: ConfirmChannel) => {
|