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