@autofleet/rabbit 3.2.14-beta.1 → 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/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": "3.0.
|
|
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",
|