@azteam/rabbitmq-async 1.0.233 → 1.0.234
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/lib/RabbitMQAsync.js +42 -34
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +10 -7
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -364,38 +364,41 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
364
364
|
key: "getInfo",
|
|
365
365
|
value: function () {
|
|
366
366
|
var _getInfo = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName) {
|
|
367
|
-
var
|
|
367
|
+
var options,
|
|
368
|
+
prefixQueueName,
|
|
369
|
+
_args6 = arguments;
|
|
368
370
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
369
371
|
while (1) switch (_context6.prev = _context6.next) {
|
|
370
372
|
case 0:
|
|
371
|
-
|
|
373
|
+
options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
|
|
374
|
+
_context6.prev = 1;
|
|
372
375
|
prefixQueueName = this.parsePrefix(queueName);
|
|
373
376
|
if (!(this.connected && this.channel)) {
|
|
374
|
-
_context6.next =
|
|
377
|
+
_context6.next = 7;
|
|
375
378
|
break;
|
|
376
379
|
}
|
|
377
|
-
_context6.next =
|
|
378
|
-
return this.channel.assertQueue(prefixQueueName, {
|
|
380
|
+
_context6.next = 6;
|
|
381
|
+
return this.channel.assertQueue(prefixQueueName, _objectSpread({
|
|
379
382
|
durable: true
|
|
380
|
-
});
|
|
381
|
-
case 5:
|
|
382
|
-
return _context6.abrupt("return", _context6.sent);
|
|
383
|
+
}, options));
|
|
383
384
|
case 6:
|
|
384
|
-
_context6.
|
|
385
|
+
return _context6.abrupt("return", _context6.sent);
|
|
386
|
+
case 7:
|
|
387
|
+
_context6.next = 11;
|
|
385
388
|
break;
|
|
386
|
-
case
|
|
387
|
-
_context6.prev =
|
|
388
|
-
_context6.t0 = _context6["catch"](
|
|
389
|
-
case
|
|
390
|
-
_context6.next =
|
|
389
|
+
case 9:
|
|
390
|
+
_context6.prev = 9;
|
|
391
|
+
_context6.t0 = _context6["catch"](1);
|
|
392
|
+
case 11:
|
|
393
|
+
_context6.next = 13;
|
|
391
394
|
return (0, _util.timeout)(2000);
|
|
392
|
-
case 12:
|
|
393
|
-
return _context6.abrupt("return", this.getInfo(queueName));
|
|
394
395
|
case 13:
|
|
396
|
+
return _context6.abrupt("return", this.getInfo(queueName, options));
|
|
397
|
+
case 14:
|
|
395
398
|
case "end":
|
|
396
399
|
return _context6.stop();
|
|
397
400
|
}
|
|
398
|
-
}, _callee6, this, [[
|
|
401
|
+
}, _callee6, this, [[1, 9]]);
|
|
399
402
|
}));
|
|
400
403
|
function getInfo(_x3) {
|
|
401
404
|
return _getInfo.apply(this, arguments);
|
|
@@ -407,6 +410,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
407
410
|
value: function () {
|
|
408
411
|
var _consume = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, asyncFunction) {
|
|
409
412
|
var callbackError,
|
|
413
|
+
options,
|
|
410
414
|
messageQueue,
|
|
411
415
|
prefixQueueName,
|
|
412
416
|
channel,
|
|
@@ -415,22 +419,23 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
415
419
|
while (1) switch (_context8.prev = _context8.next) {
|
|
416
420
|
case 0:
|
|
417
421
|
callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
|
|
422
|
+
options = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : {};
|
|
418
423
|
messageQueue = this;
|
|
419
|
-
_context8.prev =
|
|
424
|
+
_context8.prev = 3;
|
|
420
425
|
if (!(!this.connected || !this.channel)) {
|
|
421
|
-
_context8.next =
|
|
426
|
+
_context8.next = 6;
|
|
422
427
|
break;
|
|
423
428
|
}
|
|
424
429
|
return _context8.abrupt("return");
|
|
425
|
-
case
|
|
430
|
+
case 6:
|
|
426
431
|
prefixQueueName = this.parsePrefix(queueName);
|
|
427
432
|
channel = messageQueue.channel;
|
|
428
|
-
_context8.next =
|
|
429
|
-
return channel.assertQueue(prefixQueueName, {
|
|
433
|
+
_context8.next = 10;
|
|
434
|
+
return channel.assertQueue(prefixQueueName, _objectSpread({
|
|
430
435
|
durable: true
|
|
431
|
-
});
|
|
432
|
-
case
|
|
433
|
-
_context8.next =
|
|
436
|
+
}, options));
|
|
437
|
+
case 10:
|
|
438
|
+
_context8.next = 12;
|
|
434
439
|
return channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
435
440
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(msg) {
|
|
436
441
|
var data, errString;
|
|
@@ -550,23 +555,23 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
550
555
|
return _ref.apply(this, arguments);
|
|
551
556
|
};
|
|
552
557
|
}());
|
|
553
|
-
case
|
|
554
|
-
_context8.next =
|
|
558
|
+
case 12:
|
|
559
|
+
_context8.next = 18;
|
|
555
560
|
break;
|
|
556
|
-
case
|
|
557
|
-
_context8.prev =
|
|
558
|
-
_context8.t0 = _context8["catch"](
|
|
561
|
+
case 14:
|
|
562
|
+
_context8.prev = 14;
|
|
563
|
+
_context8.t0 = _context8["catch"](3);
|
|
559
564
|
this._alert('error', _context8.t0);
|
|
560
565
|
if (_lodash["default"].some(['Channel closed'], function (el) {
|
|
561
566
|
return _lodash["default"].includes(_context8.t0.toString(), el);
|
|
562
567
|
})) {
|
|
563
568
|
messageQueue.handleDisconnect();
|
|
564
569
|
}
|
|
565
|
-
case
|
|
570
|
+
case 18:
|
|
566
571
|
case "end":
|
|
567
572
|
return _context8.stop();
|
|
568
573
|
}
|
|
569
|
-
}, _callee8, this, [[
|
|
574
|
+
}, _callee8, this, [[3, 14]]);
|
|
570
575
|
}));
|
|
571
576
|
function consume(_x4, _x5) {
|
|
572
577
|
return _consume.apply(this, arguments);
|
|
@@ -580,7 +585,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
580
585
|
if (this.connected && this.channel) {
|
|
581
586
|
this.listConsume.forEach(function (c) {
|
|
582
587
|
if (!c.listened) {
|
|
583
|
-
_this3.consume(c.queueName, c.asyncFunction, c.callbackError);
|
|
588
|
+
_this3.consume(c.queueName, c.asyncFunction, c.callbackError, c.options);
|
|
584
589
|
c.listened = true;
|
|
585
590
|
}
|
|
586
591
|
});
|
|
@@ -591,11 +596,13 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
591
596
|
value: function () {
|
|
592
597
|
var _receiving = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, asyncFunction) {
|
|
593
598
|
var callbackError,
|
|
599
|
+
options,
|
|
594
600
|
_args9 = arguments;
|
|
595
601
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
596
602
|
while (1) switch (_context9.prev = _context9.next) {
|
|
597
603
|
case 0:
|
|
598
604
|
callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
|
|
605
|
+
options = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {};
|
|
599
606
|
if (!_lodash["default"].find(this.listConsume, function (c) {
|
|
600
607
|
return c.queueName === queueName;
|
|
601
608
|
})) {
|
|
@@ -603,13 +610,14 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
603
610
|
queueName: queueName,
|
|
604
611
|
asyncFunction: asyncFunction,
|
|
605
612
|
callbackError: callbackError,
|
|
613
|
+
options: options,
|
|
606
614
|
listened: false
|
|
607
615
|
});
|
|
608
616
|
if (this.connected) {
|
|
609
617
|
this.startListConsume();
|
|
610
618
|
}
|
|
611
619
|
}
|
|
612
|
-
case
|
|
620
|
+
case 3:
|
|
613
621
|
case "end":
|
|
614
622
|
return _context9.stop();
|
|
615
623
|
}
|
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -172,21 +172,22 @@ class RabbitMQAsync {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
async getInfo(queueName) {
|
|
175
|
+
async getInfo(queueName, options = {}) {
|
|
176
176
|
try {
|
|
177
177
|
const prefixQueueName = this.parsePrefix(queueName);
|
|
178
178
|
if (this.connected && this.channel) {
|
|
179
179
|
return await this.channel.assertQueue(prefixQueueName, {
|
|
180
180
|
durable: true,
|
|
181
|
+
...options,
|
|
181
182
|
});
|
|
182
183
|
}
|
|
183
184
|
} catch (err) {}
|
|
184
185
|
|
|
185
186
|
await timeout(2000);
|
|
186
|
-
return this.getInfo(queueName);
|
|
187
|
+
return this.getInfo(queueName, options);
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
async consume(queueName, asyncFunction, callbackError = null) {
|
|
190
|
+
async consume(queueName, asyncFunction, callbackError = null, options = {}) {
|
|
190
191
|
const messageQueue = this;
|
|
191
192
|
try {
|
|
192
193
|
if (!this.connected || !this.channel) return;
|
|
@@ -196,6 +197,7 @@ class RabbitMQAsync {
|
|
|
196
197
|
|
|
197
198
|
await channel.assertQueue(prefixQueueName, {
|
|
198
199
|
durable: true,
|
|
200
|
+
...options,
|
|
199
201
|
});
|
|
200
202
|
|
|
201
203
|
await channel.consume(prefixQueueName, async function (msg) {
|
|
@@ -261,19 +263,20 @@ class RabbitMQAsync {
|
|
|
261
263
|
if (this.connected && this.channel) {
|
|
262
264
|
this.listConsume.forEach((c) => {
|
|
263
265
|
if (!c.listened) {
|
|
264
|
-
this.consume(c.queueName, c.asyncFunction, c.callbackError);
|
|
266
|
+
this.consume(c.queueName, c.asyncFunction, c.callbackError, c.options);
|
|
265
267
|
c.listened = true;
|
|
266
268
|
}
|
|
267
269
|
});
|
|
268
270
|
}
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
async receiving(queueName, asyncFunction, callbackError = null) {
|
|
273
|
+
async receiving(queueName, asyncFunction, callbackError = null, options = {}) {
|
|
272
274
|
if (!_.find(this.listConsume, (c) => c.queueName === queueName)) {
|
|
273
275
|
this.listConsume.push({
|
|
274
276
|
queueName,
|
|
275
277
|
asyncFunction,
|
|
276
278
|
callbackError,
|
|
279
|
+
options,
|
|
277
280
|
listened: false,
|
|
278
281
|
});
|
|
279
282
|
if (this.connected) {
|
|
@@ -379,8 +382,8 @@ class RabbitMQAsync {
|
|
|
379
382
|
|
|
380
383
|
async sub(exchangeName, routingKey, queueName, asyncFunction, callbackError = null, type = 'fanout') {
|
|
381
384
|
const existing = queueName
|
|
382
|
-
|
|
383
|
-
|
|
385
|
+
? _.find(this.listSub, (s) => s.exchangeName === exchangeName && s.routingKey === routingKey && s.queueName === queueName)
|
|
386
|
+
: false;
|
|
384
387
|
if (!existing) {
|
|
385
388
|
this.listSub.push({
|
|
386
389
|
exchangeName,
|