@azteam/rabbitmq-async 1.0.165 → 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 +155 -106
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +8 -0
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -304,118 +304,167 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
304
304
|
return sendNoRetry;
|
|
305
305
|
}()
|
|
306
306
|
}, {
|
|
307
|
-
key: "
|
|
307
|
+
key: "selfSendNoRetry",
|
|
308
308
|
value: function () {
|
|
309
|
-
var
|
|
310
|
-
var
|
|
309
|
+
var _selfSendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName) {
|
|
310
|
+
var msg,
|
|
311
|
+
limit,
|
|
312
|
+
_args7 = arguments;
|
|
311
313
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
312
314
|
while (1) {
|
|
313
315
|
switch (_context7.prev = _context7.next) {
|
|
316
|
+
case 0:
|
|
317
|
+
msg = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
|
|
318
|
+
limit = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : 0;
|
|
319
|
+
this.selfSend(queueName, _objectSpread(_objectSpread({}, msg), {}, {
|
|
320
|
+
noRetry: true
|
|
321
|
+
}), limit);
|
|
322
|
+
case 3:
|
|
323
|
+
case "end":
|
|
324
|
+
return _context7.stop();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}, _callee7, this);
|
|
328
|
+
}));
|
|
329
|
+
function selfSendNoRetry(_x4) {
|
|
330
|
+
return _selfSendNoRetry.apply(this, arguments);
|
|
331
|
+
}
|
|
332
|
+
return selfSendNoRetry;
|
|
333
|
+
}()
|
|
334
|
+
}, {
|
|
335
|
+
key: "getInfo",
|
|
336
|
+
value: function () {
|
|
337
|
+
var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName) {
|
|
338
|
+
var prefixQueueName, channel;
|
|
339
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
340
|
+
while (1) {
|
|
341
|
+
switch (_context8.prev = _context8.next) {
|
|
314
342
|
case 0:
|
|
315
343
|
prefixQueueName = this.parsePrefix(queueName);
|
|
316
344
|
if (!this.connected) {
|
|
317
|
-
|
|
345
|
+
_context8.next = 25;
|
|
318
346
|
break;
|
|
319
347
|
}
|
|
320
|
-
|
|
321
|
-
|
|
348
|
+
_context8.prev = 2;
|
|
349
|
+
_context8.next = 5;
|
|
322
350
|
return this.client.createChannel();
|
|
323
351
|
case 5:
|
|
324
|
-
channel =
|
|
325
|
-
|
|
352
|
+
channel = _context8.sent;
|
|
353
|
+
_context8.next = 8;
|
|
326
354
|
return channel.assertQueue(prefixQueueName, {
|
|
327
355
|
durable: true
|
|
328
356
|
});
|
|
329
357
|
case 8:
|
|
330
|
-
return
|
|
358
|
+
return _context8.abrupt("return", _context8.sent);
|
|
331
359
|
case 11:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return
|
|
360
|
+
_context8.prev = 11;
|
|
361
|
+
_context8.t0 = _context8["catch"](2);
|
|
362
|
+
return _context8.abrupt("return", this.getInfo(queueName));
|
|
335
363
|
case 14:
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
364
|
+
_context8.prev = 14;
|
|
365
|
+
_context8.prev = 15;
|
|
366
|
+
_context8.next = 18;
|
|
339
367
|
return channel.close();
|
|
340
368
|
case 18:
|
|
341
|
-
|
|
369
|
+
_context8.next = 22;
|
|
342
370
|
break;
|
|
343
371
|
case 20:
|
|
344
|
-
|
|
345
|
-
|
|
372
|
+
_context8.prev = 20;
|
|
373
|
+
_context8.t1 = _context8["catch"](15);
|
|
346
374
|
case 22:
|
|
347
|
-
return
|
|
375
|
+
return _context8.finish(14);
|
|
348
376
|
case 23:
|
|
349
|
-
|
|
377
|
+
_context8.next = 26;
|
|
350
378
|
break;
|
|
351
379
|
case 25:
|
|
352
|
-
return
|
|
380
|
+
return _context8.abrupt("return", this.getInfo(queueName));
|
|
353
381
|
case 26:
|
|
354
382
|
case "end":
|
|
355
|
-
return
|
|
383
|
+
return _context8.stop();
|
|
356
384
|
}
|
|
357
385
|
}
|
|
358
|
-
},
|
|
386
|
+
}, _callee8, this, [[2, 11, 14, 23], [15, 20]]);
|
|
359
387
|
}));
|
|
360
|
-
function getInfo(
|
|
388
|
+
function getInfo(_x5) {
|
|
361
389
|
return _getInfo.apply(this, arguments);
|
|
362
390
|
}
|
|
363
391
|
return getInfo;
|
|
364
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
|
+
}()
|
|
365
414
|
}, {
|
|
366
415
|
key: "consume",
|
|
367
416
|
value: function () {
|
|
368
|
-
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
417
|
+
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(queueName, cb) {
|
|
369
418
|
var callbackError,
|
|
370
419
|
prefixQueueName,
|
|
371
420
|
channel,
|
|
372
421
|
messageQueue,
|
|
373
|
-
|
|
374
|
-
return _regeneratorRuntime().wrap(function
|
|
422
|
+
_args11 = arguments;
|
|
423
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
375
424
|
while (1) {
|
|
376
|
-
switch (
|
|
425
|
+
switch (_context11.prev = _context11.next) {
|
|
377
426
|
case 0:
|
|
378
|
-
callbackError =
|
|
427
|
+
callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
|
|
379
428
|
prefixQueueName = this.parsePrefix(queueName);
|
|
380
429
|
if (!this.connected) {
|
|
381
|
-
|
|
430
|
+
_context11.next = 30;
|
|
382
431
|
break;
|
|
383
432
|
}
|
|
384
|
-
|
|
385
|
-
|
|
433
|
+
_context11.prev = 3;
|
|
434
|
+
_context11.next = 6;
|
|
386
435
|
return this.client.createChannel();
|
|
387
436
|
case 6:
|
|
388
|
-
channel =
|
|
389
|
-
|
|
437
|
+
channel = _context11.sent;
|
|
438
|
+
_context11.next = 9;
|
|
390
439
|
return channel.assertQueue(prefixQueueName, {
|
|
391
440
|
durable: true
|
|
392
441
|
});
|
|
393
442
|
case 9:
|
|
394
|
-
|
|
443
|
+
_context11.next = 11;
|
|
395
444
|
return channel.prefetch(1);
|
|
396
445
|
case 11:
|
|
397
446
|
messageQueue = this;
|
|
398
|
-
|
|
447
|
+
_context11.next = 14;
|
|
399
448
|
return new Promise(function (resolve, reject) {
|
|
400
449
|
channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
401
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
450
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(msg) {
|
|
402
451
|
var data, errString;
|
|
403
|
-
return _regeneratorRuntime().wrap(function
|
|
452
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
404
453
|
while (1) {
|
|
405
|
-
switch (
|
|
454
|
+
switch (_context10.prev = _context10.next) {
|
|
406
455
|
case 0:
|
|
407
456
|
if (!msg) {
|
|
408
|
-
|
|
457
|
+
_context10.next = 55;
|
|
409
458
|
break;
|
|
410
459
|
}
|
|
411
460
|
data = JSON.parse(msg.content.toString());
|
|
412
461
|
if (!data) {
|
|
413
|
-
|
|
462
|
+
_context10.next = 52;
|
|
414
463
|
break;
|
|
415
464
|
}
|
|
416
|
-
|
|
465
|
+
_context10.prev = 3;
|
|
417
466
|
if (!msg.fields.redelivered) {
|
|
418
|
-
|
|
467
|
+
_context10.next = 23;
|
|
419
468
|
break;
|
|
420
469
|
}
|
|
421
470
|
if (!data.retry) {
|
|
@@ -423,143 +472,143 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
423
472
|
}
|
|
424
473
|
data.retry += 1;
|
|
425
474
|
if (!(data.retry < 5)) {
|
|
426
|
-
|
|
475
|
+
_context10.next = 17;
|
|
427
476
|
break;
|
|
428
477
|
}
|
|
429
478
|
if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
|
|
430
|
-
|
|
479
|
+
_context10.next = 13;
|
|
431
480
|
break;
|
|
432
481
|
}
|
|
433
|
-
|
|
482
|
+
_context10.next = 11;
|
|
434
483
|
return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
|
|
435
484
|
case 11:
|
|
436
|
-
|
|
485
|
+
_context10.next = 15;
|
|
437
486
|
break;
|
|
438
487
|
case 13:
|
|
439
|
-
|
|
488
|
+
_context10.next = 15;
|
|
440
489
|
return messageQueue.send(queueName, data);
|
|
441
490
|
case 15:
|
|
442
|
-
|
|
491
|
+
_context10.next = 19;
|
|
443
492
|
break;
|
|
444
493
|
case 17:
|
|
445
|
-
|
|
494
|
+
_context10.next = 19;
|
|
446
495
|
return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
447
496
|
queueName: queueName,
|
|
448
497
|
data: data,
|
|
449
498
|
retry_time: new Date()
|
|
450
499
|
});
|
|
451
500
|
case 19:
|
|
452
|
-
|
|
501
|
+
_context10.next = 21;
|
|
453
502
|
return channel.ack(msg);
|
|
454
503
|
case 21:
|
|
455
|
-
|
|
504
|
+
_context10.next = 45;
|
|
456
505
|
break;
|
|
457
506
|
case 23:
|
|
458
|
-
|
|
459
|
-
|
|
507
|
+
_context10.prev = 23;
|
|
508
|
+
_context10.next = 26;
|
|
460
509
|
return cb(data);
|
|
461
510
|
case 26:
|
|
462
|
-
|
|
511
|
+
_context10.next = 28;
|
|
463
512
|
return channel.ack(msg);
|
|
464
513
|
case 28:
|
|
465
|
-
|
|
514
|
+
_context10.next = 45;
|
|
466
515
|
break;
|
|
467
516
|
case 30:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
errString =
|
|
517
|
+
_context10.prev = 30;
|
|
518
|
+
_context10.t0 = _context10["catch"](23);
|
|
519
|
+
errString = _context10.t0.toString();
|
|
471
520
|
if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
|
|
472
521
|
return _lodash["default"].includes(errString, el);
|
|
473
522
|
})) {
|
|
474
|
-
|
|
523
|
+
_context10.next = 37;
|
|
475
524
|
break;
|
|
476
525
|
}
|
|
477
526
|
reject(new Error(errString));
|
|
478
|
-
|
|
527
|
+
_context10.next = 45;
|
|
479
528
|
break;
|
|
480
529
|
case 37:
|
|
481
530
|
if (callbackError) {
|
|
482
|
-
callbackError(prefixQueueName,
|
|
531
|
+
callbackError(prefixQueueName, _context10.t0);
|
|
483
532
|
}
|
|
484
533
|
if (!data.noRetry) {
|
|
485
|
-
|
|
534
|
+
_context10.next = 43;
|
|
486
535
|
break;
|
|
487
536
|
}
|
|
488
|
-
|
|
537
|
+
_context10.next = 41;
|
|
489
538
|
return channel.ack(msg);
|
|
490
539
|
case 41:
|
|
491
|
-
|
|
540
|
+
_context10.next = 45;
|
|
492
541
|
break;
|
|
493
542
|
case 43:
|
|
494
|
-
|
|
543
|
+
_context10.next = 45;
|
|
495
544
|
return channel.nack(msg);
|
|
496
545
|
case 45:
|
|
497
|
-
|
|
546
|
+
_context10.next = 50;
|
|
498
547
|
break;
|
|
499
548
|
case 47:
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
reject(
|
|
549
|
+
_context10.prev = 47;
|
|
550
|
+
_context10.t1 = _context10["catch"](3);
|
|
551
|
+
reject(_context10.t1);
|
|
503
552
|
case 50:
|
|
504
|
-
|
|
553
|
+
_context10.next = 53;
|
|
505
554
|
break;
|
|
506
555
|
case 52:
|
|
507
556
|
channel.ack(msg);
|
|
508
557
|
case 53:
|
|
509
|
-
|
|
558
|
+
_context10.next = 56;
|
|
510
559
|
break;
|
|
511
560
|
case 55:
|
|
512
561
|
reject(new Error('msg null'));
|
|
513
562
|
case 56:
|
|
514
563
|
case "end":
|
|
515
|
-
return
|
|
564
|
+
return _context10.stop();
|
|
516
565
|
}
|
|
517
566
|
}
|
|
518
|
-
},
|
|
567
|
+
}, _callee10, null, [[3, 47], [23, 30]]);
|
|
519
568
|
}));
|
|
520
|
-
return function (
|
|
569
|
+
return function (_x9) {
|
|
521
570
|
return _ref.apply(this, arguments);
|
|
522
571
|
};
|
|
523
572
|
}());
|
|
524
573
|
});
|
|
525
574
|
case 14:
|
|
526
|
-
|
|
575
|
+
_context11.next = 28;
|
|
527
576
|
break;
|
|
528
577
|
case 16:
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
578
|
+
_context11.prev = 16;
|
|
579
|
+
_context11.t0 = _context11["catch"](3);
|
|
580
|
+
_context11.prev = 18;
|
|
581
|
+
_context11.next = 21;
|
|
533
582
|
return channel.close();
|
|
534
583
|
case 21:
|
|
535
|
-
|
|
584
|
+
_context11.next = 25;
|
|
536
585
|
break;
|
|
537
586
|
case 23:
|
|
538
|
-
|
|
539
|
-
|
|
587
|
+
_context11.prev = 23;
|
|
588
|
+
_context11.t1 = _context11["catch"](18);
|
|
540
589
|
case 25:
|
|
541
|
-
|
|
590
|
+
_context11.next = 27;
|
|
542
591
|
return (0, _util.timeout)(5000);
|
|
543
592
|
case 27:
|
|
544
|
-
return
|
|
593
|
+
return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
545
594
|
case 28:
|
|
546
|
-
|
|
595
|
+
_context11.next = 33;
|
|
547
596
|
break;
|
|
548
597
|
case 30:
|
|
549
|
-
|
|
598
|
+
_context11.next = 32;
|
|
550
599
|
return (0, _util.timeout)(5000);
|
|
551
600
|
case 32:
|
|
552
|
-
return
|
|
601
|
+
return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
553
602
|
case 33:
|
|
554
|
-
return
|
|
603
|
+
return _context11.abrupt("return", true);
|
|
555
604
|
case 34:
|
|
556
605
|
case "end":
|
|
557
|
-
return
|
|
606
|
+
return _context11.stop();
|
|
558
607
|
}
|
|
559
608
|
}
|
|
560
|
-
},
|
|
609
|
+
}, _callee11, this, [[3, 16], [18, 23]]);
|
|
561
610
|
}));
|
|
562
|
-
function consume(
|
|
611
|
+
function consume(_x7, _x8) {
|
|
563
612
|
return _consume.apply(this, arguments);
|
|
564
613
|
}
|
|
565
614
|
return consume;
|
|
@@ -567,20 +616,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
567
616
|
}, {
|
|
568
617
|
key: "selfReceiving",
|
|
569
618
|
value: function () {
|
|
570
|
-
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
571
|
-
return _regeneratorRuntime().wrap(function
|
|
619
|
+
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(queueName, cb, callbackError) {
|
|
620
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
572
621
|
while (1) {
|
|
573
|
-
switch (
|
|
622
|
+
switch (_context12.prev = _context12.next) {
|
|
574
623
|
case 0:
|
|
575
624
|
this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
|
|
576
625
|
case 1:
|
|
577
626
|
case "end":
|
|
578
|
-
return
|
|
627
|
+
return _context12.stop();
|
|
579
628
|
}
|
|
580
629
|
}
|
|
581
|
-
},
|
|
630
|
+
}, _callee12, this);
|
|
582
631
|
}));
|
|
583
|
-
function selfReceiving(
|
|
632
|
+
function selfReceiving(_x10, _x11, _x12) {
|
|
584
633
|
return _selfReceiving.apply(this, arguments);
|
|
585
634
|
}
|
|
586
635
|
return selfReceiving;
|
|
@@ -588,26 +637,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
588
637
|
}, {
|
|
589
638
|
key: "receiving",
|
|
590
639
|
value: function () {
|
|
591
|
-
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
640
|
+
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(queueName, cb) {
|
|
592
641
|
var callbackError,
|
|
593
|
-
|
|
594
|
-
return _regeneratorRuntime().wrap(function
|
|
642
|
+
_args13 = arguments;
|
|
643
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
595
644
|
while (1) {
|
|
596
|
-
switch (
|
|
645
|
+
switch (_context13.prev = _context13.next) {
|
|
597
646
|
case 0:
|
|
598
|
-
callbackError =
|
|
647
|
+
callbackError = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : null;
|
|
599
648
|
this.consume(queueName, cb, callbackError);
|
|
600
649
|
if (this.worker) {
|
|
601
650
|
this.selfReceiving(queueName, cb, callbackError);
|
|
602
651
|
}
|
|
603
652
|
case 3:
|
|
604
653
|
case "end":
|
|
605
|
-
return
|
|
654
|
+
return _context13.stop();
|
|
606
655
|
}
|
|
607
656
|
}
|
|
608
|
-
},
|
|
657
|
+
}, _callee13, this);
|
|
609
658
|
}));
|
|
610
|
-
function receiving(
|
|
659
|
+
function receiving(_x13, _x14) {
|
|
611
660
|
return _receiving.apply(this, arguments);
|
|
612
661
|
}
|
|
613
662
|
return receiving;
|
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -112,6 +112,10 @@ class RabbitMQAsync {
|
|
|
112
112
|
this.send(queueName, {...msg, noRetry: true}, limit);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
async selfSendNoRetry(queueName, msg = {}, limit = 0) {
|
|
116
|
+
this.selfSend(queueName, {...msg, noRetry: true}, limit);
|
|
117
|
+
}
|
|
118
|
+
|
|
115
119
|
async getInfo(queueName) {
|
|
116
120
|
const prefixQueueName = this.parsePrefix(queueName);
|
|
117
121
|
|
|
@@ -134,6 +138,10 @@ class RabbitMQAsync {
|
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
async getSelfInfo(queueName) {
|
|
142
|
+
return this.getInfo(`${this.serverIp}_${queueName}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
137
145
|
async consume(queueName, cb, callbackError = null) {
|
|
138
146
|
const prefixQueueName = this.parsePrefix(queueName);
|
|
139
147
|
|