@azteam/rabbitmq-async 1.0.172 → 1.0.174
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 +45 -50
- package/package.json +2 -2
- package/src/RabbitMQAsync.js +8 -8
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -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,
|
|
326
|
-
var
|
|
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
|
-
|
|
336
|
-
prefixQueueName = this.parsePrefix(queueName);
|
|
331
|
+
prefixQueueName = this.parsePrefix(queueName, self);
|
|
337
332
|
if (!this.connected) {
|
|
338
|
-
_context7.next =
|
|
333
|
+
_context7.next = 29;
|
|
339
334
|
break;
|
|
340
335
|
}
|
|
341
|
-
_context7.prev =
|
|
342
|
-
_context7.next =
|
|
336
|
+
_context7.prev = 2;
|
|
337
|
+
_context7.next = 5;
|
|
343
338
|
return this.client.createChannel();
|
|
344
|
-
case
|
|
339
|
+
case 5:
|
|
345
340
|
channel = _context7.sent;
|
|
346
|
-
_context7.next =
|
|
341
|
+
_context7.next = 8;
|
|
347
342
|
return channel.assertQueue(prefixQueueName, {
|
|
348
343
|
durable: true
|
|
349
344
|
});
|
|
350
|
-
case
|
|
351
|
-
_context7.next =
|
|
345
|
+
case 8:
|
|
346
|
+
_context7.next = 10;
|
|
352
347
|
return channel.prefetch(1);
|
|
353
|
-
case
|
|
348
|
+
case 10:
|
|
354
349
|
messageQueue = this;
|
|
355
|
-
_context7.next =
|
|
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
|
|
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 (
|
|
471
|
+
return function (_x7) {
|
|
477
472
|
return _ref.apply(this, arguments);
|
|
478
473
|
};
|
|
479
474
|
}());
|
|
480
475
|
});
|
|
481
|
-
case
|
|
482
|
-
_context7.next =
|
|
476
|
+
case 13:
|
|
477
|
+
_context7.next = 27;
|
|
483
478
|
break;
|
|
484
|
-
case
|
|
485
|
-
_context7.prev =
|
|
486
|
-
_context7.t0 = _context7["catch"](
|
|
487
|
-
_context7.prev =
|
|
488
|
-
_context7.next =
|
|
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
|
|
491
|
-
_context7.next =
|
|
485
|
+
case 20:
|
|
486
|
+
_context7.next = 24;
|
|
492
487
|
break;
|
|
493
|
-
case
|
|
494
|
-
_context7.prev =
|
|
495
|
-
_context7.t1 = _context7["catch"](
|
|
496
|
-
case
|
|
497
|
-
_context7.next =
|
|
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
|
|
494
|
+
case 26:
|
|
500
495
|
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
501
|
-
case
|
|
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
|
|
502
|
+
case 31:
|
|
508
503
|
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
509
|
-
case
|
|
504
|
+
case 32:
|
|
510
505
|
return _context7.abrupt("return", true);
|
|
511
|
-
case
|
|
506
|
+
case 33:
|
|
512
507
|
case "end":
|
|
513
508
|
return _context7.stop();
|
|
514
509
|
}
|
|
515
510
|
}
|
|
516
|
-
}, _callee7, this, [[
|
|
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,
|
|
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(
|
|
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(
|
|
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,
|
|
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,
|
|
550
|
+
this.consume(queueName, false, asyncFunction, callbackError);
|
|
556
551
|
if (this.worker) {
|
|
557
|
-
this.selfReceiving(queueName,
|
|
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(
|
|
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.
|
|
3
|
+
"version": "1.0.174",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toda",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "babel src --delete-dir-on-start -d lib"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@azteam/util": "1.0.
|
|
19
|
+
"@azteam/util": "1.0.30",
|
|
20
20
|
"amqplib": "0.8.0",
|
|
21
21
|
"fs-extra": "10.1.0",
|
|
22
22
|
"lodash": "4.17.21"
|
package/src/RabbitMQAsync.js
CHANGED
|
@@ -130,8 +130,8 @@ class RabbitMQAsync {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async consume(queueName,
|
|
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
|
|
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,
|
|
224
|
-
this.consume(
|
|
223
|
+
async selfReceiving(queueName, asyncFunction, callbackError) {
|
|
224
|
+
this.consume(queueName, true, asyncFunction, callbackError);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
async receiving(queueName,
|
|
228
|
-
this.consume(queueName,
|
|
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,
|
|
231
|
+
this.selfReceiving(queueName, asyncFunction, callbackError);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|