@azteam/rabbitmq-async 1.0.172 → 1.0.173

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.
@@ -322,37 +322,32 @@ var RabbitMQAsync = /*#__PURE__*/function () {
322
322
  }, {
323
323
  key: "consume",
324
324
  value: function () {
325
- var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, cb) {
326
- var callbackError,
327
- prefixQueueName,
328
- channel,
329
- messageQueue,
330
- _args7 = arguments;
325
+ var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, self, asyncFunction, callbackError) {
326
+ var prefixQueueName, channel, messageQueue;
331
327
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
332
328
  while (1) {
333
329
  switch (_context7.prev = _context7.next) {
334
330
  case 0:
335
- callbackError = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
336
- prefixQueueName = this.parsePrefix(queueName);
331
+ prefixQueueName = this.parsePrefix(queueName, self);
337
332
  if (!this.connected) {
338
- _context7.next = 30;
333
+ _context7.next = 29;
339
334
  break;
340
335
  }
341
- _context7.prev = 3;
342
- _context7.next = 6;
336
+ _context7.prev = 2;
337
+ _context7.next = 5;
343
338
  return this.client.createChannel();
344
- case 6:
339
+ case 5:
345
340
  channel = _context7.sent;
346
- _context7.next = 9;
341
+ _context7.next = 8;
347
342
  return channel.assertQueue(prefixQueueName, {
348
343
  durable: true
349
344
  });
350
- case 9:
351
- _context7.next = 11;
345
+ case 8:
346
+ _context7.next = 10;
352
347
  return channel.prefetch(1);
353
- case 11:
348
+ case 10:
354
349
  messageQueue = this;
355
- _context7.next = 14;
350
+ _context7.next = 13;
356
351
  return new Promise(function (resolve, reject) {
357
352
  channel.consume(prefixQueueName, /*#__PURE__*/function () {
358
353
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(msg) {
@@ -413,7 +408,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
413
408
  case 22:
414
409
  _context6.prev = 22;
415
410
  _context6.next = 25;
416
- return cb(data);
411
+ return asyncFunction(data);
417
412
  case 25:
418
413
  _context6.next = 27;
419
414
  return channel.ack(msg);
@@ -473,49 +468,49 @@ var RabbitMQAsync = /*#__PURE__*/function () {
473
468
  }
474
469
  }, _callee6, null, [[3, 46], [22, 29]]);
475
470
  }));
476
- return function (_x5) {
471
+ return function (_x7) {
477
472
  return _ref.apply(this, arguments);
478
473
  };
479
474
  }());
480
475
  });
481
- case 14:
482
- _context7.next = 28;
476
+ case 13:
477
+ _context7.next = 27;
483
478
  break;
484
- case 16:
485
- _context7.prev = 16;
486
- _context7.t0 = _context7["catch"](3);
487
- _context7.prev = 18;
488
- _context7.next = 21;
479
+ case 15:
480
+ _context7.prev = 15;
481
+ _context7.t0 = _context7["catch"](2);
482
+ _context7.prev = 17;
483
+ _context7.next = 20;
489
484
  return channel.close();
490
- case 21:
491
- _context7.next = 25;
485
+ case 20:
486
+ _context7.next = 24;
492
487
  break;
493
- case 23:
494
- _context7.prev = 23;
495
- _context7.t1 = _context7["catch"](18);
496
- case 25:
497
- _context7.next = 27;
488
+ case 22:
489
+ _context7.prev = 22;
490
+ _context7.t1 = _context7["catch"](17);
491
+ case 24:
492
+ _context7.next = 26;
498
493
  return (0, _util.timeout)(5000);
499
- case 27:
494
+ case 26:
500
495
  return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
501
- case 28:
502
- _context7.next = 33;
503
- break;
504
- case 30:
496
+ case 27:
505
497
  _context7.next = 32;
498
+ break;
499
+ case 29:
500
+ _context7.next = 31;
506
501
  return (0, _util.timeout)(5000);
507
- case 32:
502
+ case 31:
508
503
  return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
509
- case 33:
504
+ case 32:
510
505
  return _context7.abrupt("return", true);
511
- case 34:
506
+ case 33:
512
507
  case "end":
513
508
  return _context7.stop();
514
509
  }
515
510
  }
516
- }, _callee7, this, [[3, 16], [18, 23]]);
511
+ }, _callee7, this, [[2, 15], [17, 22]]);
517
512
  }));
518
- function consume(_x3, _x4) {
513
+ function consume(_x3, _x4, _x5, _x6) {
519
514
  return _consume.apply(this, arguments);
520
515
  }
521
516
  return consume;
@@ -523,12 +518,12 @@ var RabbitMQAsync = /*#__PURE__*/function () {
523
518
  }, {
524
519
  key: "selfReceiving",
525
520
  value: function () {
526
- var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb, callbackError) {
521
+ var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, asyncFunction, callbackError) {
527
522
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
528
523
  while (1) {
529
524
  switch (_context8.prev = _context8.next) {
530
525
  case 0:
531
- this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
526
+ this.consume(queueName, true, asyncFunction, callbackError);
532
527
  case 1:
533
528
  case "end":
534
529
  return _context8.stop();
@@ -536,7 +531,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
536
531
  }
537
532
  }, _callee8, this);
538
533
  }));
539
- function selfReceiving(_x6, _x7, _x8) {
534
+ function selfReceiving(_x8, _x9, _x10) {
540
535
  return _selfReceiving.apply(this, arguments);
541
536
  }
542
537
  return selfReceiving;
@@ -544,7 +539,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
544
539
  }, {
545
540
  key: "receiving",
546
541
  value: function () {
547
- var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
542
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, asyncFunction) {
548
543
  var callbackError,
549
544
  _args9 = arguments;
550
545
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
@@ -552,9 +547,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
552
547
  switch (_context9.prev = _context9.next) {
553
548
  case 0:
554
549
  callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
555
- this.consume(queueName, cb, callbackError);
550
+ this.consume(queueName, false, asyncFunction, callbackError);
556
551
  if (this.worker) {
557
- this.selfReceiving(queueName, cb, callbackError);
552
+ this.selfReceiving(queueName, asyncFunction, callbackError);
558
553
  }
559
554
  case 3:
560
555
  case "end":
@@ -563,7 +558,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
563
558
  }
564
559
  }, _callee9, this);
565
560
  }));
566
- function receiving(_x9, _x10) {
561
+ function receiving(_x11, _x12) {
567
562
  return _receiving.apply(this, arguments);
568
563
  }
569
564
  return receiving;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.172",
3
+ "version": "1.0.173",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "toda",
@@ -130,8 +130,8 @@ class RabbitMQAsync {
130
130
  }
131
131
  }
132
132
 
133
- async consume(queueName, cb, callbackError = null) {
134
- const prefixQueueName = this.parsePrefix(queueName);
133
+ async consume(queueName, self, asyncFunction, callbackError) {
134
+ const prefixQueueName = this.parsePrefix(queueName, self);
135
135
 
136
136
  if (this.connected) {
137
137
  let channel;
@@ -174,7 +174,7 @@ class RabbitMQAsync {
174
174
  await channel.ack(msg);
175
175
  } else {
176
176
  try {
177
- await cb(data);
177
+ await asyncFunction(data);
178
178
  await channel.ack(msg);
179
179
  } catch (err) {
180
180
  const errString = err.toString();
@@ -220,15 +220,15 @@ class RabbitMQAsync {
220
220
  return true;
221
221
  }
222
222
 
223
- async selfReceiving(queueName, cb, callbackError) {
224
- this.consume(`${this.serverIp}_${queueName}`, cb, callbackError);
223
+ async selfReceiving(queueName, asyncFunction, callbackError) {
224
+ this.consume(queueName, true, asyncFunction, callbackError);
225
225
  }
226
226
 
227
- async receiving(queueName, cb, callbackError = null) {
228
- this.consume(queueName, cb, callbackError);
227
+ async receiving(queueName, asyncFunction, callbackError = null) {
228
+ this.consume(queueName, false, asyncFunction, callbackError);
229
229
 
230
230
  if (this.worker) {
231
- this.selfReceiving(queueName, cb, callbackError);
231
+ this.selfReceiving(queueName, asyncFunction, callbackError);
232
232
  }
233
233
  }
234
234