@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.
@@ -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
- _context8.prev = 1;
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 = this.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 = 7;
317
+ _context8.next = 8;
317
318
  return channel.assertQueue(prefixQueueName, {
318
319
  durable: true
319
320
  });
320
- case 7:
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(['IllegalOperationError: Channel closed'], function (el) {
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 = 17;
431
+ _context8.next = 18;
432
432
  break;
433
433
  case 12:
434
434
  _context8.prev = 12;
435
- _context8.t0 = _context8["catch"](1);
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('error', _context8.t0);
440
- // return this.consume(queueName, asyncFunction, callbackError);
441
- case 17:
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, [[1, 12]]);
449
+ }, _callee8, this, [[2, 12]]);
446
450
  }));
447
451
  function consume(_x3, _x4) {
448
452
  return _consume.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.219",
3
+ "version": "1.0.220",
4
4
  "description": "N/A",
5
5
  "keywords": [
6
6
  "toda",
@@ -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} = this;
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(['IllegalOperationError: Channel closed'], (el) => _.includes(errString, el))) {
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('error', err3);
185
- // return this.consume(queueName, asyncFunction, callbackError);
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