@azteam/rabbitmq-async 1.0.160 → 1.0.161

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.
@@ -23,6 +23,8 @@ var RabbitMQAsync = /*#__PURE__*/function () {
23
23
  this.password = config.password;
24
24
  this.host = config.host;
25
25
  this.prefix = config.prefix;
26
+ this.serverIp = config.server_ip;
27
+ this.worker = config.worker;
26
28
  this.connect();
27
29
  }
28
30
  _createClass(RabbitMQAsync, [{
@@ -304,9 +306,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
304
306
  return getInfo;
305
307
  }()
306
308
  }, {
307
- key: "receiving",
309
+ key: "consume",
308
310
  value: function () {
309
- var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, cb) {
311
+ var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, cb) {
310
312
  var callbackError,
311
313
  prefixQueueName,
312
314
  channel,
@@ -472,7 +474,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
472
474
  _context7.next = 27;
473
475
  return (0, _util.timeout)(5000);
474
476
  case 27:
475
- return _context7.abrupt("return", this.receiving(queueName, cb, callbackError));
477
+ return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
476
478
  case 28:
477
479
  _context7.next = 33;
478
480
  break;
@@ -480,15 +482,44 @@ var RabbitMQAsync = /*#__PURE__*/function () {
480
482
  _context7.next = 32;
481
483
  return (0, _util.timeout)(5000);
482
484
  case 32:
483
- return _context7.abrupt("return", this.receiving(queueName, cb, callbackError));
485
+ return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
484
486
  case 33:
487
+ return _context7.abrupt("return", true);
488
+ case 34:
485
489
  case "end":
486
490
  return _context7.stop();
487
491
  }
488
492
  }
489
493
  }, _callee7, this, [[3, 16], [18, 23]]);
490
494
  }));
491
- function receiving(_x3, _x4) {
495
+ function consume(_x3, _x4) {
496
+ return _consume.apply(this, arguments);
497
+ }
498
+ return consume;
499
+ }()
500
+ }, {
501
+ key: "receiving",
502
+ value: function () {
503
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb) {
504
+ var callbackError,
505
+ _args8 = arguments;
506
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
507
+ while (1) {
508
+ switch (_context8.prev = _context8.next) {
509
+ case 0:
510
+ callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
511
+ this.consume(queueName, cb, callbackError);
512
+ if (this.worker) {
513
+ this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
514
+ }
515
+ case 3:
516
+ case "end":
517
+ return _context8.stop();
518
+ }
519
+ }
520
+ }, _callee8, this);
521
+ }));
522
+ function receiving(_x6, _x7) {
492
523
  return _receiving.apply(this, arguments);
493
524
  }
494
525
  return receiving;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.160",
3
+ "version": "1.0.161",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./src/index.js",
@@ -9,6 +9,8 @@ class RabbitMQAsync {
9
9
  this.password = config.password;
10
10
  this.host = config.host;
11
11
  this.prefix = config.prefix;
12
+ this.serverIp = config.server_ip;
13
+ this.worker = config.worker;
12
14
  this.connect();
13
15
  }
14
16
 
@@ -124,7 +126,7 @@ class RabbitMQAsync {
124
126
  }
125
127
  }
126
128
 
127
- async receiving(queueName, cb, callbackError = null) {
129
+ async consume(queueName, cb, callbackError = null) {
128
130
  const prefixQueueName = this.parsePrefix(queueName);
129
131
 
130
132
  if (this.connected) {
@@ -201,11 +203,21 @@ class RabbitMQAsync {
201
203
  } catch (err2) {}
202
204
 
203
205
  await timeout(5000);
204
- return this.receiving(queueName, cb, callbackError);
206
+ return this.consume(queueName, cb, callbackError);
205
207
  }
206
208
  } else {
207
209
  await timeout(5000);
208
- return this.receiving(queueName, cb, callbackError);
210
+ return this.consume(queueName, cb, callbackError);
211
+ }
212
+
213
+ return true;
214
+ }
215
+
216
+ async receiving(queueName, cb, callbackError = null) {
217
+ this.consume(queueName, cb, callbackError);
218
+
219
+ if (this.worker) {
220
+ this.consume(`${this.serverIp}_${queueName}`, cb, callbackError);
209
221
  }
210
222
  }
211
223