@azteam/rabbitmq-async 1.0.166 → 1.0.167
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 +103 -82
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +4 -0
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -390,60 +390,81 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
390
390
|
}
|
|
391
391
|
return getInfo;
|
|
392
392
|
}()
|
|
393
|
+
}, {
|
|
394
|
+
key: "getSelfInfo",
|
|
395
|
+
value: function () {
|
|
396
|
+
var _getSelfInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName) {
|
|
397
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
398
|
+
while (1) {
|
|
399
|
+
switch (_context9.prev = _context9.next) {
|
|
400
|
+
case 0:
|
|
401
|
+
return _context9.abrupt("return", this.getInfo("".concat(this.serverIp, "_").concat(queueName)));
|
|
402
|
+
case 1:
|
|
403
|
+
case "end":
|
|
404
|
+
return _context9.stop();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}, _callee9, this);
|
|
408
|
+
}));
|
|
409
|
+
function getSelfInfo(_x6) {
|
|
410
|
+
return _getSelfInfo.apply(this, arguments);
|
|
411
|
+
}
|
|
412
|
+
return getSelfInfo;
|
|
413
|
+
}()
|
|
393
414
|
}, {
|
|
394
415
|
key: "consume",
|
|
395
416
|
value: function () {
|
|
396
|
-
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
417
|
+
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(queueName, cb) {
|
|
397
418
|
var callbackError,
|
|
398
419
|
prefixQueueName,
|
|
399
420
|
channel,
|
|
400
421
|
messageQueue,
|
|
401
|
-
|
|
402
|
-
return _regeneratorRuntime().wrap(function
|
|
422
|
+
_args11 = arguments;
|
|
423
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
403
424
|
while (1) {
|
|
404
|
-
switch (
|
|
425
|
+
switch (_context11.prev = _context11.next) {
|
|
405
426
|
case 0:
|
|
406
|
-
callbackError =
|
|
427
|
+
callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
|
|
407
428
|
prefixQueueName = this.parsePrefix(queueName);
|
|
408
429
|
if (!this.connected) {
|
|
409
|
-
|
|
430
|
+
_context11.next = 30;
|
|
410
431
|
break;
|
|
411
432
|
}
|
|
412
|
-
|
|
413
|
-
|
|
433
|
+
_context11.prev = 3;
|
|
434
|
+
_context11.next = 6;
|
|
414
435
|
return this.client.createChannel();
|
|
415
436
|
case 6:
|
|
416
|
-
channel =
|
|
417
|
-
|
|
437
|
+
channel = _context11.sent;
|
|
438
|
+
_context11.next = 9;
|
|
418
439
|
return channel.assertQueue(prefixQueueName, {
|
|
419
440
|
durable: true
|
|
420
441
|
});
|
|
421
442
|
case 9:
|
|
422
|
-
|
|
443
|
+
_context11.next = 11;
|
|
423
444
|
return channel.prefetch(1);
|
|
424
445
|
case 11:
|
|
425
446
|
messageQueue = this;
|
|
426
|
-
|
|
447
|
+
_context11.next = 14;
|
|
427
448
|
return new Promise(function (resolve, reject) {
|
|
428
449
|
channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
429
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
450
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(msg) {
|
|
430
451
|
var data, errString;
|
|
431
|
-
return _regeneratorRuntime().wrap(function
|
|
452
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
432
453
|
while (1) {
|
|
433
|
-
switch (
|
|
454
|
+
switch (_context10.prev = _context10.next) {
|
|
434
455
|
case 0:
|
|
435
456
|
if (!msg) {
|
|
436
|
-
|
|
457
|
+
_context10.next = 55;
|
|
437
458
|
break;
|
|
438
459
|
}
|
|
439
460
|
data = JSON.parse(msg.content.toString());
|
|
440
461
|
if (!data) {
|
|
441
|
-
|
|
462
|
+
_context10.next = 52;
|
|
442
463
|
break;
|
|
443
464
|
}
|
|
444
|
-
|
|
465
|
+
_context10.prev = 3;
|
|
445
466
|
if (!msg.fields.redelivered) {
|
|
446
|
-
|
|
467
|
+
_context10.next = 23;
|
|
447
468
|
break;
|
|
448
469
|
}
|
|
449
470
|
if (!data.retry) {
|
|
@@ -451,143 +472,143 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
451
472
|
}
|
|
452
473
|
data.retry += 1;
|
|
453
474
|
if (!(data.retry < 5)) {
|
|
454
|
-
|
|
475
|
+
_context10.next = 17;
|
|
455
476
|
break;
|
|
456
477
|
}
|
|
457
478
|
if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
|
|
458
|
-
|
|
479
|
+
_context10.next = 13;
|
|
459
480
|
break;
|
|
460
481
|
}
|
|
461
|
-
|
|
482
|
+
_context10.next = 11;
|
|
462
483
|
return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
|
|
463
484
|
case 11:
|
|
464
|
-
|
|
485
|
+
_context10.next = 15;
|
|
465
486
|
break;
|
|
466
487
|
case 13:
|
|
467
|
-
|
|
488
|
+
_context10.next = 15;
|
|
468
489
|
return messageQueue.send(queueName, data);
|
|
469
490
|
case 15:
|
|
470
|
-
|
|
491
|
+
_context10.next = 19;
|
|
471
492
|
break;
|
|
472
493
|
case 17:
|
|
473
|
-
|
|
494
|
+
_context10.next = 19;
|
|
474
495
|
return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
475
496
|
queueName: queueName,
|
|
476
497
|
data: data,
|
|
477
498
|
retry_time: new Date()
|
|
478
499
|
});
|
|
479
500
|
case 19:
|
|
480
|
-
|
|
501
|
+
_context10.next = 21;
|
|
481
502
|
return channel.ack(msg);
|
|
482
503
|
case 21:
|
|
483
|
-
|
|
504
|
+
_context10.next = 45;
|
|
484
505
|
break;
|
|
485
506
|
case 23:
|
|
486
|
-
|
|
487
|
-
|
|
507
|
+
_context10.prev = 23;
|
|
508
|
+
_context10.next = 26;
|
|
488
509
|
return cb(data);
|
|
489
510
|
case 26:
|
|
490
|
-
|
|
511
|
+
_context10.next = 28;
|
|
491
512
|
return channel.ack(msg);
|
|
492
513
|
case 28:
|
|
493
|
-
|
|
514
|
+
_context10.next = 45;
|
|
494
515
|
break;
|
|
495
516
|
case 30:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
errString =
|
|
517
|
+
_context10.prev = 30;
|
|
518
|
+
_context10.t0 = _context10["catch"](23);
|
|
519
|
+
errString = _context10.t0.toString();
|
|
499
520
|
if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
|
|
500
521
|
return _lodash["default"].includes(errString, el);
|
|
501
522
|
})) {
|
|
502
|
-
|
|
523
|
+
_context10.next = 37;
|
|
503
524
|
break;
|
|
504
525
|
}
|
|
505
526
|
reject(new Error(errString));
|
|
506
|
-
|
|
527
|
+
_context10.next = 45;
|
|
507
528
|
break;
|
|
508
529
|
case 37:
|
|
509
530
|
if (callbackError) {
|
|
510
|
-
callbackError(prefixQueueName,
|
|
531
|
+
callbackError(prefixQueueName, _context10.t0);
|
|
511
532
|
}
|
|
512
533
|
if (!data.noRetry) {
|
|
513
|
-
|
|
534
|
+
_context10.next = 43;
|
|
514
535
|
break;
|
|
515
536
|
}
|
|
516
|
-
|
|
537
|
+
_context10.next = 41;
|
|
517
538
|
return channel.ack(msg);
|
|
518
539
|
case 41:
|
|
519
|
-
|
|
540
|
+
_context10.next = 45;
|
|
520
541
|
break;
|
|
521
542
|
case 43:
|
|
522
|
-
|
|
543
|
+
_context10.next = 45;
|
|
523
544
|
return channel.nack(msg);
|
|
524
545
|
case 45:
|
|
525
|
-
|
|
546
|
+
_context10.next = 50;
|
|
526
547
|
break;
|
|
527
548
|
case 47:
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
reject(
|
|
549
|
+
_context10.prev = 47;
|
|
550
|
+
_context10.t1 = _context10["catch"](3);
|
|
551
|
+
reject(_context10.t1);
|
|
531
552
|
case 50:
|
|
532
|
-
|
|
553
|
+
_context10.next = 53;
|
|
533
554
|
break;
|
|
534
555
|
case 52:
|
|
535
556
|
channel.ack(msg);
|
|
536
557
|
case 53:
|
|
537
|
-
|
|
558
|
+
_context10.next = 56;
|
|
538
559
|
break;
|
|
539
560
|
case 55:
|
|
540
561
|
reject(new Error('msg null'));
|
|
541
562
|
case 56:
|
|
542
563
|
case "end":
|
|
543
|
-
return
|
|
564
|
+
return _context10.stop();
|
|
544
565
|
}
|
|
545
566
|
}
|
|
546
|
-
},
|
|
567
|
+
}, _callee10, null, [[3, 47], [23, 30]]);
|
|
547
568
|
}));
|
|
548
|
-
return function (
|
|
569
|
+
return function (_x9) {
|
|
549
570
|
return _ref.apply(this, arguments);
|
|
550
571
|
};
|
|
551
572
|
}());
|
|
552
573
|
});
|
|
553
574
|
case 14:
|
|
554
|
-
|
|
575
|
+
_context11.next = 28;
|
|
555
576
|
break;
|
|
556
577
|
case 16:
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
578
|
+
_context11.prev = 16;
|
|
579
|
+
_context11.t0 = _context11["catch"](3);
|
|
580
|
+
_context11.prev = 18;
|
|
581
|
+
_context11.next = 21;
|
|
561
582
|
return channel.close();
|
|
562
583
|
case 21:
|
|
563
|
-
|
|
584
|
+
_context11.next = 25;
|
|
564
585
|
break;
|
|
565
586
|
case 23:
|
|
566
|
-
|
|
567
|
-
|
|
587
|
+
_context11.prev = 23;
|
|
588
|
+
_context11.t1 = _context11["catch"](18);
|
|
568
589
|
case 25:
|
|
569
|
-
|
|
590
|
+
_context11.next = 27;
|
|
570
591
|
return (0, _util.timeout)(5000);
|
|
571
592
|
case 27:
|
|
572
|
-
return
|
|
593
|
+
return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
573
594
|
case 28:
|
|
574
|
-
|
|
595
|
+
_context11.next = 33;
|
|
575
596
|
break;
|
|
576
597
|
case 30:
|
|
577
|
-
|
|
598
|
+
_context11.next = 32;
|
|
578
599
|
return (0, _util.timeout)(5000);
|
|
579
600
|
case 32:
|
|
580
|
-
return
|
|
601
|
+
return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
581
602
|
case 33:
|
|
582
|
-
return
|
|
603
|
+
return _context11.abrupt("return", true);
|
|
583
604
|
case 34:
|
|
584
605
|
case "end":
|
|
585
|
-
return
|
|
606
|
+
return _context11.stop();
|
|
586
607
|
}
|
|
587
608
|
}
|
|
588
|
-
},
|
|
609
|
+
}, _callee11, this, [[3, 16], [18, 23]]);
|
|
589
610
|
}));
|
|
590
|
-
function consume(
|
|
611
|
+
function consume(_x7, _x8) {
|
|
591
612
|
return _consume.apply(this, arguments);
|
|
592
613
|
}
|
|
593
614
|
return consume;
|
|
@@ -595,20 +616,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
595
616
|
}, {
|
|
596
617
|
key: "selfReceiving",
|
|
597
618
|
value: function () {
|
|
598
|
-
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
599
|
-
return _regeneratorRuntime().wrap(function
|
|
619
|
+
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(queueName, cb, callbackError) {
|
|
620
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
600
621
|
while (1) {
|
|
601
|
-
switch (
|
|
622
|
+
switch (_context12.prev = _context12.next) {
|
|
602
623
|
case 0:
|
|
603
624
|
this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
|
|
604
625
|
case 1:
|
|
605
626
|
case "end":
|
|
606
|
-
return
|
|
627
|
+
return _context12.stop();
|
|
607
628
|
}
|
|
608
629
|
}
|
|
609
|
-
},
|
|
630
|
+
}, _callee12, this);
|
|
610
631
|
}));
|
|
611
|
-
function selfReceiving(
|
|
632
|
+
function selfReceiving(_x10, _x11, _x12) {
|
|
612
633
|
return _selfReceiving.apply(this, arguments);
|
|
613
634
|
}
|
|
614
635
|
return selfReceiving;
|
|
@@ -616,26 +637,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
616
637
|
}, {
|
|
617
638
|
key: "receiving",
|
|
618
639
|
value: function () {
|
|
619
|
-
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
640
|
+
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(queueName, cb) {
|
|
620
641
|
var callbackError,
|
|
621
|
-
|
|
622
|
-
return _regeneratorRuntime().wrap(function
|
|
642
|
+
_args13 = arguments;
|
|
643
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
623
644
|
while (1) {
|
|
624
|
-
switch (
|
|
645
|
+
switch (_context13.prev = _context13.next) {
|
|
625
646
|
case 0:
|
|
626
|
-
callbackError =
|
|
647
|
+
callbackError = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : null;
|
|
627
648
|
this.consume(queueName, cb, callbackError);
|
|
628
649
|
if (this.worker) {
|
|
629
650
|
this.selfReceiving(queueName, cb, callbackError);
|
|
630
651
|
}
|
|
631
652
|
case 3:
|
|
632
653
|
case "end":
|
|
633
|
-
return
|
|
654
|
+
return _context13.stop();
|
|
634
655
|
}
|
|
635
656
|
}
|
|
636
|
-
},
|
|
657
|
+
}, _callee13, this);
|
|
637
658
|
}));
|
|
638
|
-
function receiving(
|
|
659
|
+
function receiving(_x13, _x14) {
|
|
639
660
|
return _receiving.apply(this, arguments);
|
|
640
661
|
}
|
|
641
662
|
return receiving;
|
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -138,6 +138,10 @@ class RabbitMQAsync {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
async getSelfInfo(queueName) {
|
|
142
|
+
return this.getInfo(`${this.serverIp}_${queueName}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
141
145
|
async consume(queueName, cb, callbackError = null) {
|
|
142
146
|
const prefixQueueName = this.parsePrefix(queueName);
|
|
143
147
|
|