@azteam/rabbitmq-async 1.0.219 → 1.0.221

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 () {
@@ -328,17 +328,17 @@ var RabbitMQAsync = /*#__PURE__*/function () {
328
328
  while (1) switch (_context7.prev = _context7.next) {
329
329
  case 0:
330
330
  if (!msg) {
331
- _context7.next = 47;
331
+ _context7.next = 48;
332
332
  break;
333
333
  }
334
334
  data = JSON.parse(msg.content.toString());
335
335
  if (!data) {
336
- _context7.next = 46;
336
+ _context7.next = 47;
337
337
  break;
338
338
  }
339
339
  _context7.prev = 3;
340
340
  if (!msg.fields.redelivered) {
341
- _context7.next = 17;
341
+ _context7.next = 18;
342
342
  break;
343
343
  }
344
344
  data.retry -= 1;
@@ -349,78 +349,82 @@ var RabbitMQAsync = /*#__PURE__*/function () {
349
349
  _context7.next = 9;
350
350
  return messageQueue.send(queueName, data);
351
351
  case 9:
352
- _context7.next = 13;
352
+ _context7.next = 14;
353
353
  break;
354
354
  case 11:
355
- _context7.next = 13;
355
+ if (!data.notCheck) {
356
+ _context7.next = 14;
357
+ break;
358
+ }
359
+ _context7.next = 14;
356
360
  return messageQueue.send(messageQueue.parsePrefix(messageQueue.retryKey), {
357
361
  queueName: queueName,
358
362
  data: data,
359
363
  retry_time: new Date(),
360
364
  ip: messageQueue.serverIp
361
365
  });
362
- case 13:
363
- _context7.next = 15;
366
+ case 14:
367
+ _context7.next = 16;
364
368
  return channel.ack(msg);
365
- case 15:
366
- _context7.next = 39;
369
+ case 16:
370
+ _context7.next = 40;
367
371
  break;
368
- case 17:
369
- _context7.prev = 17;
370
- _context7.next = 20;
372
+ case 18:
373
+ _context7.prev = 18;
374
+ _context7.next = 21;
371
375
  return asyncFunction(data);
372
- case 20:
373
- _context7.next = 22;
376
+ case 21:
377
+ _context7.next = 23;
374
378
  return channel.ack(msg);
375
- case 22:
376
- _context7.next = 39;
379
+ case 23:
380
+ _context7.next = 40;
377
381
  break;
378
- case 24:
379
- _context7.prev = 24;
380
- _context7.t0 = _context7["catch"](17);
382
+ case 25:
383
+ _context7.prev = 25;
384
+ _context7.t0 = _context7["catch"](18);
381
385
  errString = _context7.t0.toString();
382
- if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
386
+ if (!_lodash["default"].some(['Channel closed', 'Channel closing'], function (el) {
383
387
  return _lodash["default"].includes(errString, el);
384
388
  })) {
385
- _context7.next = 31;
389
+ _context7.next = 32;
386
390
  break;
387
391
  }
388
392
  reject(_context7.t0);
389
- _context7.next = 39;
393
+ _context7.next = 40;
390
394
  break;
391
- case 31:
395
+ case 32:
392
396
  if (callbackError && data.retry === 1) {
393
397
  callbackError(prefixQueueName, errString);
394
398
  }
395
399
  if (!(data.retry <= 0)) {
396
- _context7.next = 37;
400
+ _context7.next = 38;
397
401
  break;
398
402
  }
399
- _context7.next = 35;
403
+ _context7.next = 36;
400
404
  return channel.ack(msg);
401
- case 35:
402
- _context7.next = 39;
405
+ case 36:
406
+ _context7.next = 40;
403
407
  break;
404
- case 37:
405
- _context7.next = 39;
408
+ case 38:
409
+ _context7.next = 40;
406
410
  return channel.nack(msg);
407
- case 39:
408
- _context7.next = 44;
411
+ case 40:
412
+ _context7.next = 45;
409
413
  break;
410
- case 41:
411
- _context7.prev = 41;
414
+ case 42:
415
+ _context7.prev = 42;
412
416
  _context7.t1 = _context7["catch"](3);
413
417
  reject(_context7.t1);
414
- case 44:
415
- _context7.next = 47;
418
+ case 45:
419
+ _context7.next = 48;
416
420
  break;
417
- case 46:
418
- channel.ack(msg);
419
421
  case 47:
422
+ channel.ack(msg);
423
+ case 48:
420
424
  case "end":
421
425
  return _context7.stop();
422
426
  }
423
- }, _callee7, null, [[3, 41], [17, 24]]);
427
+ }, _callee7, null, [[3, 42], [18, 25]]);
424
428
  }));
425
429
  return function (_x5) {
426
430
  return _ref2.apply(this, arguments);
@@ -428,21 +432,25 @@ var RabbitMQAsync = /*#__PURE__*/function () {
428
432
  }());
429
433
  });
430
434
  case 10:
431
- _context8.next = 17;
435
+ _context8.next = 18;
432
436
  break;
433
437
  case 12:
434
438
  _context8.prev = 12;
435
- _context8.t0 = _context8["catch"](1);
439
+ _context8.t0 = _context8["catch"](2);
436
440
  _context8.next = 16;
437
441
  return (0, _util.timeout)(5000);
438
442
  case 16:
439
- this._alert('error', _context8.t0);
440
- // return this.consume(queueName, asyncFunction, callbackError);
441
- case 17:
443
+ this._alert('err3', _context8.t0);
444
+ if (_lodash["default"].some(['Channel closed'], function (el) {
445
+ return _lodash["default"].includes(_context8.t0.toString(), el);
446
+ })) {
447
+ messageQueue.close();
448
+ }
449
+ case 18:
442
450
  case "end":
443
451
  return _context8.stop();
444
452
  }
445
- }, _callee8, this, [[1, 12]]);
453
+ }, _callee8, this, [[2, 12]]);
446
454
  }));
447
455
  function consume(_x3, _x4) {
448
456
  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.221",
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) {
@@ -139,7 +139,7 @@ class RabbitMQAsync {
139
139
  data.retry -= 1;
140
140
  if (data.retry > 0) {
141
141
  await messageQueue.send(queueName, data);
142
- } else {
142
+ } else if (data.notCheck) {
143
143
  await messageQueue.send(messageQueue.parsePrefix(messageQueue.retryKey), {
144
144
  queueName,
145
145
  data,
@@ -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