@azteam/rabbitmq-async 1.0.182 → 1.0.183

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.
@@ -98,26 +98,22 @@ var RabbitMQAsync = /*#__PURE__*/function () {
98
98
  this.client.on('error', function (err) {
99
99
  _this.connected = false;
100
100
  _this._alert('error', "MQ Error ".concat(err));
101
- if (err.toString().includes('PRECONDITION_FAILED')) {
102
- process.exit(1);
103
- }
104
- _this.reconnect();
101
+ process.exit(1);
105
102
  });
106
103
  this.client.on('close', function () {
107
104
  _this.connected = false;
108
105
  _this._alert('close', 'MQ closed');
109
- _this.reconnect();
106
+ process.exit(1);
110
107
  });
111
- _context2.next = 18;
108
+ _context2.next = 17;
112
109
  break;
113
110
  case 12:
114
111
  _context2.prev = 12;
115
112
  _context2.t0 = _context2["catch"](2);
116
113
  this.connected = false;
117
114
  this._alert('error', "MQ connect ".concat(_context2.t0));
118
- _context2.next = 18;
119
- return this.reconnect();
120
- case 18:
115
+ process.exit(1);
116
+ case 17:
121
117
  case "end":
122
118
  return _context2.stop();
123
119
  }
@@ -129,32 +125,6 @@ var RabbitMQAsync = /*#__PURE__*/function () {
129
125
  }
130
126
  return connect;
131
127
  }()
132
- }, {
133
- key: "reconnect",
134
- value: function () {
135
- var _reconnect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
136
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
137
- while (1) {
138
- switch (_context3.prev = _context3.next) {
139
- case 0:
140
- this._alert('reconnect', 'MQ try reconnect...');
141
- _context3.next = 3;
142
- return (0, _util.timeout)(5000);
143
- case 3:
144
- _context3.next = 5;
145
- return this.connect();
146
- case 5:
147
- case "end":
148
- return _context3.stop();
149
- }
150
- }
151
- }, _callee3, this);
152
- }));
153
- function reconnect() {
154
- return _reconnect.apply(this, arguments);
155
- }
156
- return reconnect;
157
- }()
158
128
  }, {
159
129
  key: "close",
160
130
  value: function close() {
@@ -177,81 +147,81 @@ var RabbitMQAsync = /*#__PURE__*/function () {
177
147
  }, {
178
148
  key: "send",
179
149
  value: function () {
180
- var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(queueName) {
150
+ var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(queueName) {
181
151
  var msg,
182
152
  limit,
183
153
  prefixQueueName,
184
154
  channel,
185
155
  queueInfo,
186
- _args4 = arguments;
187
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
156
+ _args3 = arguments;
157
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
188
158
  while (1) {
189
- switch (_context4.prev = _context4.next) {
159
+ switch (_context3.prev = _context3.next) {
190
160
  case 0:
191
- msg = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
192
- limit = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 0;
161
+ msg = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
162
+ limit = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : 0;
193
163
  prefixQueueName = this.parsePrefix(queueName, msg.self);
194
164
  if (!this.connected) {
195
- _context4.next = 33;
165
+ _context3.next = 33;
196
166
  break;
197
167
  }
198
- _context4.prev = 4;
199
- _context4.next = 7;
168
+ _context3.prev = 4;
169
+ _context3.next = 7;
200
170
  return this.client.createChannel();
201
171
  case 7:
202
- channel = _context4.sent;
203
- _context4.next = 10;
172
+ channel = _context3.sent;
173
+ _context3.next = 10;
204
174
  return channel.assertQueue(prefixQueueName, {
205
175
  durable: true
206
176
  });
207
177
  case 10:
208
- queueInfo = _context4.sent;
178
+ queueInfo = _context3.sent;
209
179
  if (!(limit === 0 || queueInfo.messageCount < limit)) {
210
- _context4.next = 14;
180
+ _context3.next = 14;
211
181
  break;
212
182
  }
213
- _context4.next = 14;
183
+ _context3.next = 14;
214
184
  return channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify(_objectSpread({
215
185
  retry: 5
216
186
  }, msg))), {
217
187
  persistent: true
218
188
  });
219
189
  case 14:
220
- return _context4.abrupt("return", true);
190
+ return _context3.abrupt("return", true);
221
191
  case 17:
222
- _context4.prev = 17;
223
- _context4.t0 = _context4["catch"](4);
224
- _context4.next = 21;
192
+ _context3.prev = 17;
193
+ _context3.t0 = _context3["catch"](4);
194
+ _context3.next = 21;
225
195
  return (0, _util.timeout)(2000);
226
196
  case 21:
227
- return _context4.abrupt("return", this.send(queueName, msg));
197
+ return _context3.abrupt("return", this.send(queueName, msg));
228
198
  case 22:
229
- _context4.prev = 22;
230
- _context4.prev = 23;
231
- _context4.next = 26;
199
+ _context3.prev = 22;
200
+ _context3.prev = 23;
201
+ _context3.next = 26;
232
202
  return channel.close();
233
203
  case 26:
234
- _context4.next = 30;
204
+ _context3.next = 30;
235
205
  break;
236
206
  case 28:
237
- _context4.prev = 28;
238
- _context4.t1 = _context4["catch"](23);
207
+ _context3.prev = 28;
208
+ _context3.t1 = _context3["catch"](23);
239
209
  case 30:
240
- return _context4.finish(22);
210
+ return _context3.finish(22);
241
211
  case 31:
242
- _context4.next = 36;
212
+ _context3.next = 36;
243
213
  break;
244
214
  case 33:
245
- _context4.next = 35;
215
+ _context3.next = 35;
246
216
  return (0, _util.timeout)(2000);
247
217
  case 35:
248
- return _context4.abrupt("return", this.send(queueName, msg));
218
+ return _context3.abrupt("return", this.send(queueName, msg));
249
219
  case 36:
250
220
  case "end":
251
- return _context4.stop();
221
+ return _context3.stop();
252
222
  }
253
223
  }
254
- }, _callee4, this, [[4, 17, 22, 31], [23, 28]]);
224
+ }, _callee3, this, [[4, 17, 22, 31], [23, 28]]);
255
225
  }));
256
226
  function send(_x) {
257
227
  return _send.apply(this, arguments);
@@ -261,60 +231,60 @@ var RabbitMQAsync = /*#__PURE__*/function () {
261
231
  }, {
262
232
  key: "getInfo",
263
233
  value: function () {
264
- var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
234
+ var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(queueName) {
265
235
  var self,
266
236
  prefixQueueName,
267
237
  channel,
268
- _args5 = arguments;
269
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
238
+ _args4 = arguments;
239
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
270
240
  while (1) {
271
- switch (_context5.prev = _context5.next) {
241
+ switch (_context4.prev = _context4.next) {
272
242
  case 0:
273
- self = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : false;
243
+ self = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : false;
274
244
  prefixQueueName = this.parsePrefix(queueName, self);
275
245
  if (!this.connected) {
276
- _context5.next = 26;
246
+ _context4.next = 26;
277
247
  break;
278
248
  }
279
- _context5.prev = 3;
280
- _context5.next = 6;
249
+ _context4.prev = 3;
250
+ _context4.next = 6;
281
251
  return this.client.createChannel();
282
252
  case 6:
283
- channel = _context5.sent;
284
- _context5.next = 9;
253
+ channel = _context4.sent;
254
+ _context4.next = 9;
285
255
  return channel.assertQueue(prefixQueueName, {
286
256
  durable: true
287
257
  });
288
258
  case 9:
289
- return _context5.abrupt("return", _context5.sent);
259
+ return _context4.abrupt("return", _context4.sent);
290
260
  case 12:
291
- _context5.prev = 12;
292
- _context5.t0 = _context5["catch"](3);
293
- return _context5.abrupt("return", this.getInfo(queueName));
261
+ _context4.prev = 12;
262
+ _context4.t0 = _context4["catch"](3);
263
+ return _context4.abrupt("return", this.getInfo(queueName));
294
264
  case 15:
295
- _context5.prev = 15;
296
- _context5.prev = 16;
297
- _context5.next = 19;
265
+ _context4.prev = 15;
266
+ _context4.prev = 16;
267
+ _context4.next = 19;
298
268
  return channel.close();
299
269
  case 19:
300
- _context5.next = 23;
270
+ _context4.next = 23;
301
271
  break;
302
272
  case 21:
303
- _context5.prev = 21;
304
- _context5.t1 = _context5["catch"](16);
273
+ _context4.prev = 21;
274
+ _context4.t1 = _context4["catch"](16);
305
275
  case 23:
306
- return _context5.finish(15);
276
+ return _context4.finish(15);
307
277
  case 24:
308
- _context5.next = 27;
278
+ _context4.next = 27;
309
279
  break;
310
280
  case 26:
311
- return _context5.abrupt("return", this.getInfo(queueName));
281
+ return _context4.abrupt("return", this.getInfo(queueName));
312
282
  case 27:
313
283
  case "end":
314
- return _context5.stop();
284
+ return _context4.stop();
315
285
  }
316
286
  }
317
- }, _callee5, this, [[3, 12, 15, 24], [16, 21]]);
287
+ }, _callee4, this, [[3, 12, 15, 24], [16, 21]]);
318
288
  }));
319
289
  function getInfo(_x2) {
320
290
  return _getInfo.apply(this, arguments);
@@ -324,151 +294,151 @@ var RabbitMQAsync = /*#__PURE__*/function () {
324
294
  }, {
325
295
  key: "consume",
326
296
  value: function () {
327
- var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, self, asyncFunction, callbackError) {
297
+ var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName, self, asyncFunction, callbackError) {
328
298
  var prefixQueueName, channel, messageQueue;
329
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
299
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
330
300
  while (1) {
331
- switch (_context7.prev = _context7.next) {
301
+ switch (_context6.prev = _context6.next) {
332
302
  case 0:
333
303
  prefixQueueName = this.parsePrefix(queueName, self);
334
304
  if (!this.connected) {
335
- _context7.next = 29;
305
+ _context6.next = 29;
336
306
  break;
337
307
  }
338
- _context7.prev = 2;
339
- _context7.next = 5;
308
+ _context6.prev = 2;
309
+ _context6.next = 5;
340
310
  return this.client.createChannel();
341
311
  case 5:
342
- channel = _context7.sent;
343
- _context7.next = 8;
312
+ channel = _context6.sent;
313
+ _context6.next = 8;
344
314
  return channel.assertQueue(prefixQueueName, {
345
315
  durable: true
346
316
  });
347
317
  case 8:
348
- _context7.next = 10;
318
+ _context6.next = 10;
349
319
  return channel.prefetch(1);
350
320
  case 10:
351
321
  messageQueue = this;
352
- _context7.next = 13;
322
+ _context6.next = 13;
353
323
  return new Promise(function (resolve, reject) {
354
324
  channel.consume(prefixQueueName, /*#__PURE__*/function () {
355
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(msg) {
325
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(msg) {
356
326
  var data, errString;
357
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
327
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
358
328
  while (1) {
359
- switch (_context6.prev = _context6.next) {
329
+ switch (_context5.prev = _context5.next) {
360
330
  case 0:
361
331
  if (!msg) {
362
- _context6.next = 54;
332
+ _context5.next = 54;
363
333
  break;
364
334
  }
365
335
  data = JSON.parse(msg.content.toString());
366
336
  if (!data) {
367
- _context6.next = 51;
337
+ _context5.next = 51;
368
338
  break;
369
339
  }
370
- _context6.prev = 3;
340
+ _context5.prev = 3;
371
341
  if (!msg.fields.redelivered) {
372
- _context6.next = 22;
342
+ _context5.next = 22;
373
343
  break;
374
344
  }
375
345
  data.retry -= 1;
376
346
  if (!(data.retry > 0)) {
377
- _context6.next = 16;
347
+ _context5.next = 16;
378
348
  break;
379
349
  }
380
350
  if (!messageQueue.worker) {
381
- _context6.next = 12;
351
+ _context5.next = 12;
382
352
  break;
383
353
  }
384
- _context6.next = 10;
354
+ _context5.next = 10;
385
355
  return messageQueue.send(queueName, _objectSpread(_objectSpread({}, data), {}, {
386
356
  self: true
387
357
  }));
388
358
  case 10:
389
- _context6.next = 14;
359
+ _context5.next = 14;
390
360
  break;
391
361
  case 12:
392
- _context6.next = 14;
362
+ _context5.next = 14;
393
363
  return messageQueue.send(queueName, data);
394
364
  case 14:
395
- _context6.next = 18;
365
+ _context5.next = 18;
396
366
  break;
397
367
  case 16:
398
- _context6.next = 18;
368
+ _context5.next = 18;
399
369
  return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
400
370
  queueName: queueName,
401
371
  data: data,
402
372
  retry_time: new Date()
403
373
  });
404
374
  case 18:
405
- _context6.next = 20;
375
+ _context5.next = 20;
406
376
  return channel.ack(msg);
407
377
  case 20:
408
- _context6.next = 44;
378
+ _context5.next = 44;
409
379
  break;
410
380
  case 22:
411
- _context6.prev = 22;
412
- _context6.next = 25;
381
+ _context5.prev = 22;
382
+ _context5.next = 25;
413
383
  return asyncFunction(data);
414
384
  case 25:
415
- _context6.next = 27;
385
+ _context5.next = 27;
416
386
  return channel.ack(msg);
417
387
  case 27:
418
- _context6.next = 44;
388
+ _context5.next = 44;
419
389
  break;
420
390
  case 29:
421
- _context6.prev = 29;
422
- _context6.t0 = _context6["catch"](22);
423
- errString = _context6.t0.toString();
391
+ _context5.prev = 29;
392
+ _context5.t0 = _context5["catch"](22);
393
+ errString = _context5.t0.toString();
424
394
  if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
425
395
  return _lodash["default"].includes(errString, el);
426
396
  })) {
427
- _context6.next = 36;
397
+ _context5.next = 36;
428
398
  break;
429
399
  }
430
400
  reject(new Error(errString));
431
- _context6.next = 44;
401
+ _context5.next = 44;
432
402
  break;
433
403
  case 36:
434
404
  if (callbackError) {
435
- callbackError(prefixQueueName, _context6.t0);
405
+ callbackError(prefixQueueName, _context5.t0);
436
406
  }
437
407
  if (!(data.retry <= 0)) {
438
- _context6.next = 42;
408
+ _context5.next = 42;
439
409
  break;
440
410
  }
441
- _context6.next = 40;
411
+ _context5.next = 40;
442
412
  return channel.ack(msg);
443
413
  case 40:
444
- _context6.next = 44;
414
+ _context5.next = 44;
445
415
  break;
446
416
  case 42:
447
- _context6.next = 44;
417
+ _context5.next = 44;
448
418
  return channel.nack(msg);
449
419
  case 44:
450
- _context6.next = 49;
420
+ _context5.next = 49;
451
421
  break;
452
422
  case 46:
453
- _context6.prev = 46;
454
- _context6.t1 = _context6["catch"](3);
455
- reject(_context6.t1);
423
+ _context5.prev = 46;
424
+ _context5.t1 = _context5["catch"](3);
425
+ reject(_context5.t1);
456
426
  case 49:
457
- _context6.next = 52;
427
+ _context5.next = 52;
458
428
  break;
459
429
  case 51:
460
430
  channel.ack(msg);
461
431
  case 52:
462
- _context6.next = 55;
432
+ _context5.next = 55;
463
433
  break;
464
434
  case 54:
465
435
  reject(new Error('msg null'));
466
436
  case 55:
467
437
  case "end":
468
- return _context6.stop();
438
+ return _context5.stop();
469
439
  }
470
440
  }
471
- }, _callee6, null, [[3, 46], [22, 29]]);
441
+ }, _callee5, null, [[3, 46], [22, 29]]);
472
442
  }));
473
443
  return function (_x7) {
474
444
  return _ref.apply(this, arguments);
@@ -476,41 +446,41 @@ var RabbitMQAsync = /*#__PURE__*/function () {
476
446
  }());
477
447
  });
478
448
  case 13:
479
- _context7.next = 27;
449
+ _context6.next = 27;
480
450
  break;
481
451
  case 15:
482
- _context7.prev = 15;
483
- _context7.t0 = _context7["catch"](2);
484
- _context7.prev = 17;
485
- _context7.next = 20;
452
+ _context6.prev = 15;
453
+ _context6.t0 = _context6["catch"](2);
454
+ _context6.prev = 17;
455
+ _context6.next = 20;
486
456
  return channel.close();
487
457
  case 20:
488
- _context7.next = 24;
458
+ _context6.next = 24;
489
459
  break;
490
460
  case 22:
491
- _context7.prev = 22;
492
- _context7.t1 = _context7["catch"](17);
461
+ _context6.prev = 22;
462
+ _context6.t1 = _context6["catch"](17);
493
463
  case 24:
494
- _context7.next = 26;
464
+ _context6.next = 26;
495
465
  return (0, _util.timeout)(5000);
496
466
  case 26:
497
- return _context7.abrupt("return", this.consume(queueName, self, asyncFunction, callbackError));
467
+ return _context6.abrupt("return", this.consume(queueName, self, asyncFunction, callbackError));
498
468
  case 27:
499
- _context7.next = 32;
469
+ _context6.next = 32;
500
470
  break;
501
471
  case 29:
502
- _context7.next = 31;
472
+ _context6.next = 31;
503
473
  return (0, _util.timeout)(5000);
504
474
  case 31:
505
- return _context7.abrupt("return", this.consume(queueName, self, asyncFunction, callbackError));
475
+ return _context6.abrupt("return", this.consume(queueName, self, asyncFunction, callbackError));
506
476
  case 32:
507
- return _context7.abrupt("return", true);
477
+ return _context6.abrupt("return", true);
508
478
  case 33:
509
479
  case "end":
510
- return _context7.stop();
480
+ return _context6.stop();
511
481
  }
512
482
  }
513
- }, _callee7, this, [[2, 15], [17, 22]]);
483
+ }, _callee6, this, [[2, 15], [17, 22]]);
514
484
  }));
515
485
  function consume(_x3, _x4, _x5, _x6) {
516
486
  return _consume.apply(this, arguments);
@@ -520,18 +490,18 @@ var RabbitMQAsync = /*#__PURE__*/function () {
520
490
  }, {
521
491
  key: "selfReceiving",
522
492
  value: function () {
523
- var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, asyncFunction, callbackError) {
524
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
493
+ var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, asyncFunction, callbackError) {
494
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
525
495
  while (1) {
526
- switch (_context8.prev = _context8.next) {
496
+ switch (_context7.prev = _context7.next) {
527
497
  case 0:
528
498
  this.consume(queueName, true, asyncFunction, callbackError);
529
499
  case 1:
530
500
  case "end":
531
- return _context8.stop();
501
+ return _context7.stop();
532
502
  }
533
503
  }
534
- }, _callee8, this);
504
+ }, _callee7, this);
535
505
  }));
536
506
  function selfReceiving(_x8, _x9, _x10) {
537
507
  return _selfReceiving.apply(this, arguments);
@@ -541,24 +511,24 @@ var RabbitMQAsync = /*#__PURE__*/function () {
541
511
  }, {
542
512
  key: "receiving",
543
513
  value: function () {
544
- var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, asyncFunction) {
514
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, asyncFunction) {
545
515
  var callbackError,
546
- _args9 = arguments;
547
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
516
+ _args8 = arguments;
517
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
548
518
  while (1) {
549
- switch (_context9.prev = _context9.next) {
519
+ switch (_context8.prev = _context8.next) {
550
520
  case 0:
551
- callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
521
+ callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
552
522
  this.consume(queueName, false, asyncFunction, callbackError);
553
523
  if (this.worker) {
554
524
  this.selfReceiving(queueName, asyncFunction, callbackError);
555
525
  }
556
526
  case 3:
557
527
  case "end":
558
- return _context9.stop();
528
+ return _context8.stop();
559
529
  }
560
530
  }
561
- }, _callee9, this);
531
+ }, _callee8, this);
562
532
  }));
563
533
  function receiving(_x11, _x12) {
564
534
  return _receiving.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.182",
3
+ "version": "1.0.183",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "toda",
@@ -35,31 +35,21 @@ class RabbitMQAsync {
35
35
  this.connected = false;
36
36
  this._alert('error', `MQ Error ${err}`);
37
37
 
38
- if (err.toString().includes('PRECONDITION_FAILED')) {
39
- process.exit(1);
40
- }
41
-
42
- this.reconnect();
38
+ process.exit(1);
43
39
  });
44
40
 
45
41
  this.client.on('close', () => {
46
42
  this.connected = false;
47
43
  this._alert('close', 'MQ closed');
48
- this.reconnect();
44
+ process.exit(1);
49
45
  });
50
46
  } catch (err) {
51
47
  this.connected = false;
52
48
  this._alert('error', `MQ connect ${err}`);
53
- await this.reconnect();
49
+ process.exit(1);
54
50
  }
55
51
  }
56
52
 
57
- async reconnect() {
58
- this._alert('reconnect', 'MQ try reconnect...');
59
- await timeout(5000);
60
- await this.connect();
61
- }
62
-
63
53
  close() {
64
54
  this.connected = false;
65
55
  this.client.close();