@azteam/rabbitmq-async 1.0.164 → 1.0.165

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.
@@ -250,9 +250,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
250
250
  return send;
251
251
  }()
252
252
  }, {
253
- key: "sendNoRetry",
253
+ key: "selfSend",
254
254
  value: function () {
255
- var _sendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
255
+ var _selfSend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
256
256
  var msg,
257
257
  limit,
258
258
  _args5 = arguments;
@@ -262,17 +262,43 @@ var RabbitMQAsync = /*#__PURE__*/function () {
262
262
  case 0:
263
263
  msg = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
264
264
  limit = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 0;
265
+ this.send("".concat(this.serverIp, "_").concat(queueName), msg, limit);
266
+ case 3:
267
+ case "end":
268
+ return _context5.stop();
269
+ }
270
+ }
271
+ }, _callee5, this);
272
+ }));
273
+ function selfSend(_x2) {
274
+ return _selfSend.apply(this, arguments);
275
+ }
276
+ return selfSend;
277
+ }()
278
+ }, {
279
+ key: "sendNoRetry",
280
+ value: function () {
281
+ var _sendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName) {
282
+ var msg,
283
+ limit,
284
+ _args6 = arguments;
285
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
286
+ while (1) {
287
+ switch (_context6.prev = _context6.next) {
288
+ case 0:
289
+ msg = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
290
+ limit = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 0;
265
291
  this.send(queueName, _objectSpread(_objectSpread({}, msg), {}, {
266
292
  noRetry: true
267
293
  }), limit);
268
294
  case 3:
269
295
  case "end":
270
- return _context5.stop();
296
+ return _context6.stop();
271
297
  }
272
298
  }
273
- }, _callee5, this);
299
+ }, _callee6, this);
274
300
  }));
275
- function sendNoRetry(_x2) {
301
+ function sendNoRetry(_x3) {
276
302
  return _sendNoRetry.apply(this, arguments);
277
303
  }
278
304
  return sendNoRetry;
@@ -280,58 +306,58 @@ var RabbitMQAsync = /*#__PURE__*/function () {
280
306
  }, {
281
307
  key: "getInfo",
282
308
  value: function () {
283
- var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName) {
309
+ var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName) {
284
310
  var prefixQueueName, channel;
285
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
311
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
286
312
  while (1) {
287
- switch (_context6.prev = _context6.next) {
313
+ switch (_context7.prev = _context7.next) {
288
314
  case 0:
289
315
  prefixQueueName = this.parsePrefix(queueName);
290
316
  if (!this.connected) {
291
- _context6.next = 25;
317
+ _context7.next = 25;
292
318
  break;
293
319
  }
294
- _context6.prev = 2;
295
- _context6.next = 5;
320
+ _context7.prev = 2;
321
+ _context7.next = 5;
296
322
  return this.client.createChannel();
297
323
  case 5:
298
- channel = _context6.sent;
299
- _context6.next = 8;
324
+ channel = _context7.sent;
325
+ _context7.next = 8;
300
326
  return channel.assertQueue(prefixQueueName, {
301
327
  durable: true
302
328
  });
303
329
  case 8:
304
- return _context6.abrupt("return", _context6.sent);
330
+ return _context7.abrupt("return", _context7.sent);
305
331
  case 11:
306
- _context6.prev = 11;
307
- _context6.t0 = _context6["catch"](2);
308
- return _context6.abrupt("return", this.getInfo(queueName));
332
+ _context7.prev = 11;
333
+ _context7.t0 = _context7["catch"](2);
334
+ return _context7.abrupt("return", this.getInfo(queueName));
309
335
  case 14:
310
- _context6.prev = 14;
311
- _context6.prev = 15;
312
- _context6.next = 18;
336
+ _context7.prev = 14;
337
+ _context7.prev = 15;
338
+ _context7.next = 18;
313
339
  return channel.close();
314
340
  case 18:
315
- _context6.next = 22;
341
+ _context7.next = 22;
316
342
  break;
317
343
  case 20:
318
- _context6.prev = 20;
319
- _context6.t1 = _context6["catch"](15);
344
+ _context7.prev = 20;
345
+ _context7.t1 = _context7["catch"](15);
320
346
  case 22:
321
- return _context6.finish(14);
347
+ return _context7.finish(14);
322
348
  case 23:
323
- _context6.next = 26;
349
+ _context7.next = 26;
324
350
  break;
325
351
  case 25:
326
- return _context6.abrupt("return", this.getInfo(queueName));
352
+ return _context7.abrupt("return", this.getInfo(queueName));
327
353
  case 26:
328
354
  case "end":
329
- return _context6.stop();
355
+ return _context7.stop();
330
356
  }
331
357
  }
332
- }, _callee6, this, [[2, 11, 14, 23], [15, 20]]);
358
+ }, _callee7, this, [[2, 11, 14, 23], [15, 20]]);
333
359
  }));
334
- function getInfo(_x3) {
360
+ function getInfo(_x4) {
335
361
  return _getInfo.apply(this, arguments);
336
362
  }
337
363
  return getInfo;
@@ -339,57 +365,57 @@ var RabbitMQAsync = /*#__PURE__*/function () {
339
365
  }, {
340
366
  key: "consume",
341
367
  value: function () {
342
- var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb) {
368
+ var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
343
369
  var callbackError,
344
370
  prefixQueueName,
345
371
  channel,
346
372
  messageQueue,
347
- _args8 = arguments;
348
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
373
+ _args9 = arguments;
374
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
349
375
  while (1) {
350
- switch (_context8.prev = _context8.next) {
376
+ switch (_context9.prev = _context9.next) {
351
377
  case 0:
352
- callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
378
+ callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
353
379
  prefixQueueName = this.parsePrefix(queueName);
354
380
  if (!this.connected) {
355
- _context8.next = 30;
381
+ _context9.next = 30;
356
382
  break;
357
383
  }
358
- _context8.prev = 3;
359
- _context8.next = 6;
384
+ _context9.prev = 3;
385
+ _context9.next = 6;
360
386
  return this.client.createChannel();
361
387
  case 6:
362
- channel = _context8.sent;
363
- _context8.next = 9;
388
+ channel = _context9.sent;
389
+ _context9.next = 9;
364
390
  return channel.assertQueue(prefixQueueName, {
365
391
  durable: true
366
392
  });
367
393
  case 9:
368
- _context8.next = 11;
394
+ _context9.next = 11;
369
395
  return channel.prefetch(1);
370
396
  case 11:
371
397
  messageQueue = this;
372
- _context8.next = 14;
398
+ _context9.next = 14;
373
399
  return new Promise(function (resolve, reject) {
374
400
  channel.consume(prefixQueueName, /*#__PURE__*/function () {
375
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(msg) {
401
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(msg) {
376
402
  var data, errString;
377
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
403
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
378
404
  while (1) {
379
- switch (_context7.prev = _context7.next) {
405
+ switch (_context8.prev = _context8.next) {
380
406
  case 0:
381
407
  if (!msg) {
382
- _context7.next = 55;
408
+ _context8.next = 55;
383
409
  break;
384
410
  }
385
411
  data = JSON.parse(msg.content.toString());
386
412
  if (!data) {
387
- _context7.next = 52;
413
+ _context8.next = 52;
388
414
  break;
389
415
  }
390
- _context7.prev = 3;
416
+ _context8.prev = 3;
391
417
  if (!msg.fields.redelivered) {
392
- _context7.next = 23;
418
+ _context8.next = 23;
393
419
  break;
394
420
  }
395
421
  if (!data.retry) {
@@ -397,143 +423,143 @@ var RabbitMQAsync = /*#__PURE__*/function () {
397
423
  }
398
424
  data.retry += 1;
399
425
  if (!(data.retry < 5)) {
400
- _context7.next = 17;
426
+ _context8.next = 17;
401
427
  break;
402
428
  }
403
429
  if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
404
- _context7.next = 13;
430
+ _context8.next = 13;
405
431
  break;
406
432
  }
407
- _context7.next = 11;
433
+ _context8.next = 11;
408
434
  return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
409
435
  case 11:
410
- _context7.next = 15;
436
+ _context8.next = 15;
411
437
  break;
412
438
  case 13:
413
- _context7.next = 15;
439
+ _context8.next = 15;
414
440
  return messageQueue.send(queueName, data);
415
441
  case 15:
416
- _context7.next = 19;
442
+ _context8.next = 19;
417
443
  break;
418
444
  case 17:
419
- _context7.next = 19;
445
+ _context8.next = 19;
420
446
  return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
421
447
  queueName: queueName,
422
448
  data: data,
423
449
  retry_time: new Date()
424
450
  });
425
451
  case 19:
426
- _context7.next = 21;
452
+ _context8.next = 21;
427
453
  return channel.ack(msg);
428
454
  case 21:
429
- _context7.next = 45;
455
+ _context8.next = 45;
430
456
  break;
431
457
  case 23:
432
- _context7.prev = 23;
433
- _context7.next = 26;
458
+ _context8.prev = 23;
459
+ _context8.next = 26;
434
460
  return cb(data);
435
461
  case 26:
436
- _context7.next = 28;
462
+ _context8.next = 28;
437
463
  return channel.ack(msg);
438
464
  case 28:
439
- _context7.next = 45;
465
+ _context8.next = 45;
440
466
  break;
441
467
  case 30:
442
- _context7.prev = 30;
443
- _context7.t0 = _context7["catch"](23);
444
- errString = _context7.t0.toString();
468
+ _context8.prev = 30;
469
+ _context8.t0 = _context8["catch"](23);
470
+ errString = _context8.t0.toString();
445
471
  if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
446
472
  return _lodash["default"].includes(errString, el);
447
473
  })) {
448
- _context7.next = 37;
474
+ _context8.next = 37;
449
475
  break;
450
476
  }
451
477
  reject(new Error(errString));
452
- _context7.next = 45;
478
+ _context8.next = 45;
453
479
  break;
454
480
  case 37:
455
481
  if (callbackError) {
456
- callbackError(prefixQueueName, _context7.t0);
482
+ callbackError(prefixQueueName, _context8.t0);
457
483
  }
458
484
  if (!data.noRetry) {
459
- _context7.next = 43;
485
+ _context8.next = 43;
460
486
  break;
461
487
  }
462
- _context7.next = 41;
488
+ _context8.next = 41;
463
489
  return channel.ack(msg);
464
490
  case 41:
465
- _context7.next = 45;
491
+ _context8.next = 45;
466
492
  break;
467
493
  case 43:
468
- _context7.next = 45;
494
+ _context8.next = 45;
469
495
  return channel.nack(msg);
470
496
  case 45:
471
- _context7.next = 50;
497
+ _context8.next = 50;
472
498
  break;
473
499
  case 47:
474
- _context7.prev = 47;
475
- _context7.t1 = _context7["catch"](3);
476
- reject(_context7.t1);
500
+ _context8.prev = 47;
501
+ _context8.t1 = _context8["catch"](3);
502
+ reject(_context8.t1);
477
503
  case 50:
478
- _context7.next = 53;
504
+ _context8.next = 53;
479
505
  break;
480
506
  case 52:
481
507
  channel.ack(msg);
482
508
  case 53:
483
- _context7.next = 56;
509
+ _context8.next = 56;
484
510
  break;
485
511
  case 55:
486
512
  reject(new Error('msg null'));
487
513
  case 56:
488
514
  case "end":
489
- return _context7.stop();
515
+ return _context8.stop();
490
516
  }
491
517
  }
492
- }, _callee7, null, [[3, 47], [23, 30]]);
518
+ }, _callee8, null, [[3, 47], [23, 30]]);
493
519
  }));
494
- return function (_x6) {
520
+ return function (_x7) {
495
521
  return _ref.apply(this, arguments);
496
522
  };
497
523
  }());
498
524
  });
499
525
  case 14:
500
- _context8.next = 28;
526
+ _context9.next = 28;
501
527
  break;
502
528
  case 16:
503
- _context8.prev = 16;
504
- _context8.t0 = _context8["catch"](3);
505
- _context8.prev = 18;
506
- _context8.next = 21;
529
+ _context9.prev = 16;
530
+ _context9.t0 = _context9["catch"](3);
531
+ _context9.prev = 18;
532
+ _context9.next = 21;
507
533
  return channel.close();
508
534
  case 21:
509
- _context8.next = 25;
535
+ _context9.next = 25;
510
536
  break;
511
537
  case 23:
512
- _context8.prev = 23;
513
- _context8.t1 = _context8["catch"](18);
538
+ _context9.prev = 23;
539
+ _context9.t1 = _context9["catch"](18);
514
540
  case 25:
515
- _context8.next = 27;
541
+ _context9.next = 27;
516
542
  return (0, _util.timeout)(5000);
517
543
  case 27:
518
- return _context8.abrupt("return", this.consume(queueName, cb, callbackError));
544
+ return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
519
545
  case 28:
520
- _context8.next = 33;
546
+ _context9.next = 33;
521
547
  break;
522
548
  case 30:
523
- _context8.next = 32;
549
+ _context9.next = 32;
524
550
  return (0, _util.timeout)(5000);
525
551
  case 32:
526
- return _context8.abrupt("return", this.consume(queueName, cb, callbackError));
552
+ return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
527
553
  case 33:
528
- return _context8.abrupt("return", true);
554
+ return _context9.abrupt("return", true);
529
555
  case 34:
530
556
  case "end":
531
- return _context8.stop();
557
+ return _context9.stop();
532
558
  }
533
559
  }
534
- }, _callee8, this, [[3, 16], [18, 23]]);
560
+ }, _callee9, this, [[3, 16], [18, 23]]);
535
561
  }));
536
- function consume(_x4, _x5) {
562
+ function consume(_x5, _x6) {
537
563
  return _consume.apply(this, arguments);
538
564
  }
539
565
  return consume;
@@ -541,20 +567,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
541
567
  }, {
542
568
  key: "selfReceiving",
543
569
  value: function () {
544
- var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb, callbackError) {
545
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
570
+ var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(queueName, cb, callbackError) {
571
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
546
572
  while (1) {
547
- switch (_context9.prev = _context9.next) {
573
+ switch (_context10.prev = _context10.next) {
548
574
  case 0:
549
575
  this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
550
576
  case 1:
551
577
  case "end":
552
- return _context9.stop();
578
+ return _context10.stop();
553
579
  }
554
580
  }
555
- }, _callee9, this);
581
+ }, _callee10, this);
556
582
  }));
557
- function selfReceiving(_x7, _x8, _x9) {
583
+ function selfReceiving(_x8, _x9, _x10) {
558
584
  return _selfReceiving.apply(this, arguments);
559
585
  }
560
586
  return selfReceiving;
@@ -562,26 +588,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
562
588
  }, {
563
589
  key: "receiving",
564
590
  value: function () {
565
- var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(queueName, cb) {
591
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(queueName, cb) {
566
592
  var callbackError,
567
- _args10 = arguments;
568
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
593
+ _args11 = arguments;
594
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
569
595
  while (1) {
570
- switch (_context10.prev = _context10.next) {
596
+ switch (_context11.prev = _context11.next) {
571
597
  case 0:
572
- callbackError = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : null;
598
+ callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
573
599
  this.consume(queueName, cb, callbackError);
574
600
  if (this.worker) {
575
601
  this.selfReceiving(queueName, cb, callbackError);
576
602
  }
577
603
  case 3:
578
604
  case "end":
579
- return _context10.stop();
605
+ return _context11.stop();
580
606
  }
581
607
  }
582
- }, _callee10, this);
608
+ }, _callee11, this);
583
609
  }));
584
- function receiving(_x10, _x11) {
610
+ function receiving(_x11, _x12) {
585
611
  return _receiving.apply(this, arguments);
586
612
  }
587
613
  return receiving;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.164",
3
+ "version": "1.0.165",
4
4
  "description": "",
5
- "main": "./lib/index.js",
6
- "module": "./src/index.js",
7
- "scripts": {
8
- "build": "babel src --delete-dir-on-start -d lib"
9
- },
10
5
  "keywords": [
11
6
  "toda",
12
7
  "nodejs",
13
8
  "rabbitmq",
14
9
  "rabbitmq async"
15
10
  ],
16
- "author": "toda <sp.azsolution.net@gmail.com>",
17
11
  "license": "MIT",
12
+ "author": "toda <sp.azsolution.net@gmail.com>",
13
+ "main": "./lib/index.js",
14
+ "module": "./src/index.js",
15
+ "scripts": {
16
+ "build": "babel src --delete-dir-on-start -d lib"
17
+ },
18
18
  "dependencies": {
19
19
  "@azteam/util": "1.0.29",
20
20
  "amqplib": "0.8.0",
@@ -104,6 +104,10 @@ class RabbitMQAsync {
104
104
  }
105
105
  }
106
106
 
107
+ async selfSend(queueName, msg = {}, limit = 0) {
108
+ this.send(`${this.serverIp}_${queueName}`, msg, limit);
109
+ }
110
+
107
111
  async sendNoRetry(queueName, msg = {}, limit = 0) {
108
112
  this.send(queueName, {...msg, noRetry: true}, limit);
109
113
  }