@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.
@@ -304,118 +304,167 @@ var RabbitMQAsync = /*#__PURE__*/function () {
304
304
  return sendNoRetry;
305
305
  }()
306
306
  }, {
307
- key: "getInfo",
307
+ key: "selfSendNoRetry",
308
308
  value: function () {
309
- var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName) {
310
- var prefixQueueName, channel;
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
- _context7.next = 25;
345
+ _context8.next = 25;
318
346
  break;
319
347
  }
320
- _context7.prev = 2;
321
- _context7.next = 5;
348
+ _context8.prev = 2;
349
+ _context8.next = 5;
322
350
  return this.client.createChannel();
323
351
  case 5:
324
- channel = _context7.sent;
325
- _context7.next = 8;
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 _context7.abrupt("return", _context7.sent);
358
+ return _context8.abrupt("return", _context8.sent);
331
359
  case 11:
332
- _context7.prev = 11;
333
- _context7.t0 = _context7["catch"](2);
334
- return _context7.abrupt("return", this.getInfo(queueName));
360
+ _context8.prev = 11;
361
+ _context8.t0 = _context8["catch"](2);
362
+ return _context8.abrupt("return", this.getInfo(queueName));
335
363
  case 14:
336
- _context7.prev = 14;
337
- _context7.prev = 15;
338
- _context7.next = 18;
364
+ _context8.prev = 14;
365
+ _context8.prev = 15;
366
+ _context8.next = 18;
339
367
  return channel.close();
340
368
  case 18:
341
- _context7.next = 22;
369
+ _context8.next = 22;
342
370
  break;
343
371
  case 20:
344
- _context7.prev = 20;
345
- _context7.t1 = _context7["catch"](15);
372
+ _context8.prev = 20;
373
+ _context8.t1 = _context8["catch"](15);
346
374
  case 22:
347
- return _context7.finish(14);
375
+ return _context8.finish(14);
348
376
  case 23:
349
- _context7.next = 26;
377
+ _context8.next = 26;
350
378
  break;
351
379
  case 25:
352
- return _context7.abrupt("return", this.getInfo(queueName));
380
+ return _context8.abrupt("return", this.getInfo(queueName));
353
381
  case 26:
354
382
  case "end":
355
- return _context7.stop();
383
+ return _context8.stop();
356
384
  }
357
385
  }
358
- }, _callee7, this, [[2, 11, 14, 23], [15, 20]]);
386
+ }, _callee8, this, [[2, 11, 14, 23], [15, 20]]);
359
387
  }));
360
- function getInfo(_x4) {
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 _callee9(queueName, cb) {
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
- _args9 = arguments;
374
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
422
+ _args11 = arguments;
423
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
375
424
  while (1) {
376
- switch (_context9.prev = _context9.next) {
425
+ switch (_context11.prev = _context11.next) {
377
426
  case 0:
378
- callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
427
+ callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
379
428
  prefixQueueName = this.parsePrefix(queueName);
380
429
  if (!this.connected) {
381
- _context9.next = 30;
430
+ _context11.next = 30;
382
431
  break;
383
432
  }
384
- _context9.prev = 3;
385
- _context9.next = 6;
433
+ _context11.prev = 3;
434
+ _context11.next = 6;
386
435
  return this.client.createChannel();
387
436
  case 6:
388
- channel = _context9.sent;
389
- _context9.next = 9;
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
- _context9.next = 11;
443
+ _context11.next = 11;
395
444
  return channel.prefetch(1);
396
445
  case 11:
397
446
  messageQueue = this;
398
- _context9.next = 14;
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 _callee8(msg) {
450
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(msg) {
402
451
  var data, errString;
403
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
452
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
404
453
  while (1) {
405
- switch (_context8.prev = _context8.next) {
454
+ switch (_context10.prev = _context10.next) {
406
455
  case 0:
407
456
  if (!msg) {
408
- _context8.next = 55;
457
+ _context10.next = 55;
409
458
  break;
410
459
  }
411
460
  data = JSON.parse(msg.content.toString());
412
461
  if (!data) {
413
- _context8.next = 52;
462
+ _context10.next = 52;
414
463
  break;
415
464
  }
416
- _context8.prev = 3;
465
+ _context10.prev = 3;
417
466
  if (!msg.fields.redelivered) {
418
- _context8.next = 23;
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
- _context8.next = 17;
475
+ _context10.next = 17;
427
476
  break;
428
477
  }
429
478
  if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
430
- _context8.next = 13;
479
+ _context10.next = 13;
431
480
  break;
432
481
  }
433
- _context8.next = 11;
482
+ _context10.next = 11;
434
483
  return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
435
484
  case 11:
436
- _context8.next = 15;
485
+ _context10.next = 15;
437
486
  break;
438
487
  case 13:
439
- _context8.next = 15;
488
+ _context10.next = 15;
440
489
  return messageQueue.send(queueName, data);
441
490
  case 15:
442
- _context8.next = 19;
491
+ _context10.next = 19;
443
492
  break;
444
493
  case 17:
445
- _context8.next = 19;
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
- _context8.next = 21;
501
+ _context10.next = 21;
453
502
  return channel.ack(msg);
454
503
  case 21:
455
- _context8.next = 45;
504
+ _context10.next = 45;
456
505
  break;
457
506
  case 23:
458
- _context8.prev = 23;
459
- _context8.next = 26;
507
+ _context10.prev = 23;
508
+ _context10.next = 26;
460
509
  return cb(data);
461
510
  case 26:
462
- _context8.next = 28;
511
+ _context10.next = 28;
463
512
  return channel.ack(msg);
464
513
  case 28:
465
- _context8.next = 45;
514
+ _context10.next = 45;
466
515
  break;
467
516
  case 30:
468
- _context8.prev = 30;
469
- _context8.t0 = _context8["catch"](23);
470
- errString = _context8.t0.toString();
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
- _context8.next = 37;
523
+ _context10.next = 37;
475
524
  break;
476
525
  }
477
526
  reject(new Error(errString));
478
- _context8.next = 45;
527
+ _context10.next = 45;
479
528
  break;
480
529
  case 37:
481
530
  if (callbackError) {
482
- callbackError(prefixQueueName, _context8.t0);
531
+ callbackError(prefixQueueName, _context10.t0);
483
532
  }
484
533
  if (!data.noRetry) {
485
- _context8.next = 43;
534
+ _context10.next = 43;
486
535
  break;
487
536
  }
488
- _context8.next = 41;
537
+ _context10.next = 41;
489
538
  return channel.ack(msg);
490
539
  case 41:
491
- _context8.next = 45;
540
+ _context10.next = 45;
492
541
  break;
493
542
  case 43:
494
- _context8.next = 45;
543
+ _context10.next = 45;
495
544
  return channel.nack(msg);
496
545
  case 45:
497
- _context8.next = 50;
546
+ _context10.next = 50;
498
547
  break;
499
548
  case 47:
500
- _context8.prev = 47;
501
- _context8.t1 = _context8["catch"](3);
502
- reject(_context8.t1);
549
+ _context10.prev = 47;
550
+ _context10.t1 = _context10["catch"](3);
551
+ reject(_context10.t1);
503
552
  case 50:
504
- _context8.next = 53;
553
+ _context10.next = 53;
505
554
  break;
506
555
  case 52:
507
556
  channel.ack(msg);
508
557
  case 53:
509
- _context8.next = 56;
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 _context8.stop();
564
+ return _context10.stop();
516
565
  }
517
566
  }
518
- }, _callee8, null, [[3, 47], [23, 30]]);
567
+ }, _callee10, null, [[3, 47], [23, 30]]);
519
568
  }));
520
- return function (_x7) {
569
+ return function (_x9) {
521
570
  return _ref.apply(this, arguments);
522
571
  };
523
572
  }());
524
573
  });
525
574
  case 14:
526
- _context9.next = 28;
575
+ _context11.next = 28;
527
576
  break;
528
577
  case 16:
529
- _context9.prev = 16;
530
- _context9.t0 = _context9["catch"](3);
531
- _context9.prev = 18;
532
- _context9.next = 21;
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
- _context9.next = 25;
584
+ _context11.next = 25;
536
585
  break;
537
586
  case 23:
538
- _context9.prev = 23;
539
- _context9.t1 = _context9["catch"](18);
587
+ _context11.prev = 23;
588
+ _context11.t1 = _context11["catch"](18);
540
589
  case 25:
541
- _context9.next = 27;
590
+ _context11.next = 27;
542
591
  return (0, _util.timeout)(5000);
543
592
  case 27:
544
- return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
593
+ return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
545
594
  case 28:
546
- _context9.next = 33;
595
+ _context11.next = 33;
547
596
  break;
548
597
  case 30:
549
- _context9.next = 32;
598
+ _context11.next = 32;
550
599
  return (0, _util.timeout)(5000);
551
600
  case 32:
552
- return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
601
+ return _context11.abrupt("return", this.consume(queueName, cb, callbackError));
553
602
  case 33:
554
- return _context9.abrupt("return", true);
603
+ return _context11.abrupt("return", true);
555
604
  case 34:
556
605
  case "end":
557
- return _context9.stop();
606
+ return _context11.stop();
558
607
  }
559
608
  }
560
- }, _callee9, this, [[3, 16], [18, 23]]);
609
+ }, _callee11, this, [[3, 16], [18, 23]]);
561
610
  }));
562
- function consume(_x5, _x6) {
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 _callee10(queueName, cb, callbackError) {
571
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
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 (_context10.prev = _context10.next) {
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 _context10.stop();
627
+ return _context12.stop();
579
628
  }
580
629
  }
581
- }, _callee10, this);
630
+ }, _callee12, this);
582
631
  }));
583
- function selfReceiving(_x8, _x9, _x10) {
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 _callee11(queueName, cb) {
640
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(queueName, cb) {
592
641
  var callbackError,
593
- _args11 = arguments;
594
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
642
+ _args13 = arguments;
643
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
595
644
  while (1) {
596
- switch (_context11.prev = _context11.next) {
645
+ switch (_context13.prev = _context13.next) {
597
646
  case 0:
598
- callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
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 _context11.stop();
654
+ return _context13.stop();
606
655
  }
607
656
  }
608
- }, _callee11, this);
657
+ }, _callee13, this);
609
658
  }));
610
- function receiving(_x11, _x12) {
659
+ function receiving(_x13, _x14) {
611
660
  return _receiving.apply(this, arguments);
612
661
  }
613
662
  return receiving;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.165",
3
+ "version": "1.0.167",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "toda",
@@ -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