@azteam/rabbitmq-async 1.0.219 → 1.0.220
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 +17 -13
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +7 -5
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -295,30 +295,30 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
295
295
|
value: function () {
|
|
296
296
|
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, asyncFunction) {
|
|
297
297
|
var callbackError,
|
|
298
|
+
messageQueue,
|
|
298
299
|
prefixQueueName,
|
|
299
300
|
channel,
|
|
300
|
-
messageQueue,
|
|
301
301
|
_args8 = arguments;
|
|
302
302
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
303
303
|
while (1) switch (_context8.prev = _context8.next) {
|
|
304
304
|
case 0:
|
|
305
305
|
callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
|
|
306
|
-
|
|
306
|
+
messageQueue = this;
|
|
307
|
+
_context8.prev = 2;
|
|
307
308
|
if (!this.connected) {
|
|
308
309
|
_context8.next = 10;
|
|
309
310
|
break;
|
|
310
311
|
}
|
|
311
|
-
prefixQueueName = this.parsePrefix(queueName), channel =
|
|
312
|
+
prefixQueueName = this.parsePrefix(queueName), channel = messageQueue.channel;
|
|
312
313
|
if (!channel) {
|
|
313
314
|
_context8.next = 10;
|
|
314
315
|
break;
|
|
315
316
|
}
|
|
316
|
-
_context8.next =
|
|
317
|
+
_context8.next = 8;
|
|
317
318
|
return channel.assertQueue(prefixQueueName, {
|
|
318
319
|
durable: true
|
|
319
320
|
});
|
|
320
|
-
case
|
|
321
|
-
messageQueue = this;
|
|
321
|
+
case 8:
|
|
322
322
|
_context8.next = 10;
|
|
323
323
|
return new Promise(function (resolve, reject) {
|
|
324
324
|
channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
@@ -379,7 +379,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
379
379
|
_context7.prev = 24;
|
|
380
380
|
_context7.t0 = _context7["catch"](17);
|
|
381
381
|
errString = _context7.t0.toString();
|
|
382
|
-
if (!_lodash["default"].some(['
|
|
382
|
+
if (!_lodash["default"].some(['Channel closed', 'Channel closing'], function (el) {
|
|
383
383
|
return _lodash["default"].includes(errString, el);
|
|
384
384
|
})) {
|
|
385
385
|
_context7.next = 31;
|
|
@@ -428,21 +428,25 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
428
428
|
}());
|
|
429
429
|
});
|
|
430
430
|
case 10:
|
|
431
|
-
_context8.next =
|
|
431
|
+
_context8.next = 18;
|
|
432
432
|
break;
|
|
433
433
|
case 12:
|
|
434
434
|
_context8.prev = 12;
|
|
435
|
-
_context8.t0 = _context8["catch"](
|
|
435
|
+
_context8.t0 = _context8["catch"](2);
|
|
436
436
|
_context8.next = 16;
|
|
437
437
|
return (0, _util.timeout)(5000);
|
|
438
438
|
case 16:
|
|
439
|
-
this._alert('
|
|
440
|
-
|
|
441
|
-
|
|
439
|
+
this._alert('err3', _context8.t0);
|
|
440
|
+
if (_lodash["default"].some(['Channel closed'], function (el) {
|
|
441
|
+
return _lodash["default"].includes(_context8.t0.toString(), el);
|
|
442
|
+
})) {
|
|
443
|
+
messageQueue.close();
|
|
444
|
+
}
|
|
445
|
+
case 18:
|
|
442
446
|
case "end":
|
|
443
447
|
return _context8.stop();
|
|
444
448
|
}
|
|
445
|
-
}, _callee8, this, [[
|
|
449
|
+
}, _callee8, this, [[2, 12]]);
|
|
446
450
|
}));
|
|
447
451
|
function consume(_x3, _x4) {
|
|
448
452
|
return _consume.apply(this, arguments);
|
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -120,15 +120,15 @@ class RabbitMQAsync {
|
|
|
120
120
|
|
|
121
121
|
// eslint-disable-next-line consistent-return
|
|
122
122
|
async consume(queueName, asyncFunction, callbackError = null) {
|
|
123
|
+
const messageQueue = this;
|
|
123
124
|
try {
|
|
124
125
|
if (this.connected) {
|
|
125
126
|
const prefixQueueName = this.parsePrefix(queueName),
|
|
126
|
-
{channel} =
|
|
127
|
+
{channel} = messageQueue;
|
|
127
128
|
if (channel) {
|
|
128
129
|
await channel.assertQueue(prefixQueueName, {
|
|
129
130
|
durable: true,
|
|
130
131
|
});
|
|
131
|
-
const messageQueue = this;
|
|
132
132
|
await new Promise((resolve, reject) => {
|
|
133
133
|
channel.consume(prefixQueueName, async function (msg) {
|
|
134
134
|
if (msg) {
|
|
@@ -154,7 +154,7 @@ class RabbitMQAsync {
|
|
|
154
154
|
await channel.ack(msg);
|
|
155
155
|
} catch (err1) {
|
|
156
156
|
const errString = err1.toString();
|
|
157
|
-
if (_.some(['
|
|
157
|
+
if (_.some(['Channel closed', 'Channel closing'], (el) => _.includes(errString, el))) {
|
|
158
158
|
reject(err1);
|
|
159
159
|
} else {
|
|
160
160
|
if (callbackError && data.retry === 1) {
|
|
@@ -181,8 +181,10 @@ class RabbitMQAsync {
|
|
|
181
181
|
}
|
|
182
182
|
} catch (err3) {
|
|
183
183
|
await timeout(5000);
|
|
184
|
-
this._alert('
|
|
185
|
-
|
|
184
|
+
this._alert('err3', err3);
|
|
185
|
+
if (_.some(['Channel closed'], (el) => _.includes(err3.toString(), el))) {
|
|
186
|
+
messageQueue.close();
|
|
187
|
+
}
|
|
186
188
|
}
|
|
187
189
|
}
|
|
188
190
|
|