@autofleet/rabbit 3.2.14-beta.0 → 3.2.14-beta.2
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 +25 -40
- package/package.json +3 -3
- package/src/index.ts +25 -40
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable no-empty,consistent-return,no-async-promise-executor,@typescript-eslint/no-unused-vars */
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
4
|
};
|
|
@@ -217,38 +216,29 @@ class RabbitMq {
|
|
|
217
216
|
}
|
|
218
217
|
async getNewChannel({ name = utils_1.rand().toString(), onClose = null, options = {} } = {}) {
|
|
219
218
|
return new Promise(async (resolve, reject) => {
|
|
220
|
-
|
|
221
|
-
|
|
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({
|
|
219
|
+
const connection = await this.getConnection();
|
|
220
|
+
const channel = connection.createChannel({
|
|
229
221
|
...options,
|
|
230
222
|
});
|
|
231
223
|
let isResolved = false;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (!isResolved) {
|
|
236
|
-
isResolved = true;
|
|
237
|
-
reject(err);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
channel.on('close', (...args) => {
|
|
241
|
-
logger_1.default.error(`rabbit: channel ${name} closed`, { args });
|
|
242
|
-
if (onClose) {
|
|
243
|
-
onClose(args);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
channel.once('connect', () => {
|
|
247
|
-
debug(`rabbit: channel ${name} CONNECTED`);
|
|
224
|
+
channel.on('error', (err) => {
|
|
225
|
+
logger_1.default.error(`rabbit: channel error ${name} error`, { err });
|
|
226
|
+
if (!isResolved) {
|
|
248
227
|
isResolved = true;
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
}
|
|
228
|
+
reject(err);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
channel.on('close', (...args) => {
|
|
232
|
+
logger_1.default.error(`rabbit: channel ${name} closed`, { args });
|
|
233
|
+
if (onClose) {
|
|
234
|
+
onClose(args);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
channel.once('connect', () => {
|
|
238
|
+
debug(`rabbit: channel ${name} CONNECTED`);
|
|
239
|
+
isResolved = true;
|
|
240
|
+
resolve(channel);
|
|
241
|
+
});
|
|
252
242
|
});
|
|
253
243
|
}
|
|
254
244
|
async assertChannel({ force = false } = {}) {
|
|
@@ -332,18 +322,15 @@ class RabbitMq {
|
|
|
332
322
|
return queue;
|
|
333
323
|
}
|
|
334
324
|
saveConsumer(queue, callback, options) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
callback,
|
|
341
|
-
options,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
325
|
+
this.consumers.push({
|
|
326
|
+
queue,
|
|
327
|
+
callback,
|
|
328
|
+
options,
|
|
329
|
+
});
|
|
344
330
|
}
|
|
345
331
|
async consume(queue, callback, options) {
|
|
346
332
|
await this.consumeFromRabbit(queue, callback, options);
|
|
333
|
+
return this.saveConsumer(queue, callback, options);
|
|
347
334
|
}
|
|
348
335
|
async lockRedisIfNeeded(msg, options) {
|
|
349
336
|
const { properties: { headers } } = msg;
|
|
@@ -362,7 +349,6 @@ class RabbitMq {
|
|
|
362
349
|
async consumeFromRabbit(queue, callback, options) {
|
|
363
350
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
364
351
|
RabbitMq.validateName('queue', queue);
|
|
365
|
-
this.saveConsumer(queue, callback, options);
|
|
366
352
|
const uniqueId = uuid_1.v4();
|
|
367
353
|
const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace, } = optionsWithDefaults;
|
|
368
354
|
if (useConsumeWithLock) {
|
|
@@ -451,7 +437,6 @@ class RabbitMq {
|
|
|
451
437
|
RabbitMq.validateName('exchange', exchange);
|
|
452
438
|
RabbitMq.validateName('queue', queue);
|
|
453
439
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
454
|
-
await this.saveConsumer(queue, callback, options);
|
|
455
440
|
const channel = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
|
|
456
441
|
return channel.addSetup(async (c) => {
|
|
457
442
|
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.14-beta.
|
|
3
|
+
"version": "3.2.14-beta.2",
|
|
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.6",
|
|
20
20
|
"@types/amqplib": "0.8.2",
|
|
21
21
|
"@types/uuid": "^8.3.3",
|
|
22
22
|
"amqp-connection-manager": "4.1.9",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"uuid": "^8.3.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@autofleet/outbreak": "
|
|
31
|
+
"@autofleet/outbreak": "0.2.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "^26.0.23",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-empty,consistent-return,no-async-promise-executor,@typescript-eslint/no-unused-vars */
|
|
2
|
-
|
|
3
1
|
import { EventEmitter } from 'events';
|
|
4
2
|
import { promisify } from 'util';
|
|
5
3
|
import moment from 'moment';
|
|
@@ -350,38 +348,30 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
350
348
|
|
|
351
349
|
async getNewChannel({ name = rand().toString(), onClose = null, options = {} }: newChannelOpts = {}) {
|
|
352
350
|
return new Promise<ChannelWrapper>(async (resolve, reject) => {
|
|
353
|
-
|
|
354
|
-
|
|
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({
|
|
351
|
+
const connection: AmqpConnectionManager = await this.getConnection();
|
|
352
|
+
const channel = connection.createChannel({
|
|
361
353
|
...options,
|
|
362
354
|
});
|
|
363
355
|
|
|
364
356
|
let isResolved = false;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (!isResolved) {
|
|
369
|
-
isResolved = true;
|
|
370
|
-
reject(err);
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
channel.on('close', (...args) => {
|
|
374
|
-
logger.error(`rabbit: channel ${name} closed`, { args });
|
|
375
|
-
if (onClose) {
|
|
376
|
-
onClose(args);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
channel.once('connect', () => {
|
|
380
|
-
debug(`rabbit: channel ${name} CONNECTED`);
|
|
357
|
+
channel.on('error', (err) => {
|
|
358
|
+
logger.error(`rabbit: channel error ${name} error`, { err });
|
|
359
|
+
if (!isResolved) {
|
|
381
360
|
isResolved = true;
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
}
|
|
361
|
+
reject(err);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
channel.on('close', (...args) => {
|
|
365
|
+
logger.error(`rabbit: channel ${name} closed`, { args });
|
|
366
|
+
if (onClose) {
|
|
367
|
+
onClose(args);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
channel.once('connect', () => {
|
|
371
|
+
debug(`rabbit: channel ${name} CONNECTED`);
|
|
372
|
+
isResolved = true;
|
|
373
|
+
resolve(channel);
|
|
374
|
+
});
|
|
385
375
|
});
|
|
386
376
|
}
|
|
387
377
|
|
|
@@ -472,19 +462,16 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
472
462
|
}
|
|
473
463
|
|
|
474
464
|
private saveConsumer(queue: string, callback: CallbackFunction, options: ConsumeOptions | undefined) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
callback,
|
|
481
|
-
options,
|
|
482
|
-
});
|
|
483
|
-
}
|
|
465
|
+
this.consumers.push({
|
|
466
|
+
queue,
|
|
467
|
+
callback,
|
|
468
|
+
options,
|
|
469
|
+
});
|
|
484
470
|
}
|
|
485
471
|
|
|
486
472
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
487
473
|
await this.consumeFromRabbit(queue, callback, options);
|
|
474
|
+
return this.saveConsumer(queue, callback, options);
|
|
488
475
|
}
|
|
489
476
|
|
|
490
477
|
private async lockRedisIfNeeded(msg: any, options: any) {
|
|
@@ -510,7 +497,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
510
497
|
private async consumeFromRabbit(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
511
498
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
512
499
|
RabbitMq.validateName('queue', queue);
|
|
513
|
-
this.saveConsumer(queue, callback, options);
|
|
514
500
|
const uniqueId = v4();
|
|
515
501
|
const {
|
|
516
502
|
limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace,
|
|
@@ -613,7 +599,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
613
599
|
RabbitMq.validateName('exchange', exchange);
|
|
614
600
|
RabbitMq.validateName('queue', queue);
|
|
615
601
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
616
|
-
await this.saveConsumer(queue, callback, options);
|
|
617
602
|
const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
|
|
618
603
|
|
|
619
604
|
return channel.addSetup(async (c: ConfirmChannel) => {
|