@azteam/rabbitmq-async 1.0.163 → 1.0.165

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.
@@ -9,6 +9,9 @@ var _lodash = _interopRequireDefault(require("lodash"));
9
9
  var _amqplib = _interopRequireDefault(require("amqplib"));
10
10
  var _util = require("@azteam/util");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
15
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
13
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
14
17
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -179,7 +182,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
179
182
  switch (_context4.prev = _context4.next) {
180
183
  case 0:
181
184
  msg = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
182
- limit = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
185
+ limit = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 0;
183
186
  prefixQueueName = this.parsePrefix(queueName);
184
187
  if (!this.connected) {
185
188
  _context4.next = 33;
@@ -196,7 +199,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
196
199
  });
197
200
  case 10:
198
201
  queueInfo = _context4.sent;
199
- if (!(!limit || queueInfo.messageCount < limit)) {
202
+ if (!(limit === 0 || queueInfo.messageCount < limit)) {
200
203
  _context4.next = 14;
201
204
  break;
202
205
  }
@@ -247,9 +250,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
247
250
  return send;
248
251
  }()
249
252
  }, {
250
- key: "sendNoRetry",
253
+ key: "selfSend",
251
254
  value: function () {
252
- var _sendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
255
+ var _selfSend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
253
256
  var msg,
254
257
  limit,
255
258
  _args5 = arguments;
@@ -258,8 +261,8 @@ var RabbitMQAsync = /*#__PURE__*/function () {
258
261
  switch (_context5.prev = _context5.next) {
259
262
  case 0:
260
263
  msg = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
261
- limit = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
262
- this.send(queueName, msg, limit);
264
+ limit = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 0;
265
+ this.send("".concat(this.serverIp, "_").concat(queueName), msg, limit);
263
266
  case 3:
264
267
  case "end":
265
268
  return _context5.stop();
@@ -267,7 +270,35 @@ var RabbitMQAsync = /*#__PURE__*/function () {
267
270
  }
268
271
  }, _callee5, this);
269
272
  }));
270
- function sendNoRetry(_x2) {
273
+ function selfSend(_x2) {
274
+ return _selfSend.apply(this, arguments);
275
+ }
276
+ return selfSend;
277
+ }()
278
+ }, {
279
+ key: "sendNoRetry",
280
+ value: function () {
281
+ var _sendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName) {
282
+ var msg,
283
+ limit,
284
+ _args6 = arguments;
285
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
286
+ while (1) {
287
+ switch (_context6.prev = _context6.next) {
288
+ case 0:
289
+ msg = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
290
+ limit = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 0;
291
+ this.send(queueName, _objectSpread(_objectSpread({}, msg), {}, {
292
+ noRetry: true
293
+ }), limit);
294
+ case 3:
295
+ case "end":
296
+ return _context6.stop();
297
+ }
298
+ }
299
+ }, _callee6, this);
300
+ }));
301
+ function sendNoRetry(_x3) {
271
302
  return _sendNoRetry.apply(this, arguments);
272
303
  }
273
304
  return sendNoRetry;
@@ -275,58 +306,58 @@ var RabbitMQAsync = /*#__PURE__*/function () {
275
306
  }, {
276
307
  key: "getInfo",
277
308
  value: function () {
278
- var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(queueName) {
309
+ var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName) {
279
310
  var prefixQueueName, channel;
280
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
311
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
281
312
  while (1) {
282
- switch (_context6.prev = _context6.next) {
313
+ switch (_context7.prev = _context7.next) {
283
314
  case 0:
284
315
  prefixQueueName = this.parsePrefix(queueName);
285
316
  if (!this.connected) {
286
- _context6.next = 25;
317
+ _context7.next = 25;
287
318
  break;
288
319
  }
289
- _context6.prev = 2;
290
- _context6.next = 5;
320
+ _context7.prev = 2;
321
+ _context7.next = 5;
291
322
  return this.client.createChannel();
292
323
  case 5:
293
- channel = _context6.sent;
294
- _context6.next = 8;
324
+ channel = _context7.sent;
325
+ _context7.next = 8;
295
326
  return channel.assertQueue(prefixQueueName, {
296
327
  durable: true
297
328
  });
298
329
  case 8:
299
- return _context6.abrupt("return", _context6.sent);
330
+ return _context7.abrupt("return", _context7.sent);
300
331
  case 11:
301
- _context6.prev = 11;
302
- _context6.t0 = _context6["catch"](2);
303
- return _context6.abrupt("return", this.getInfo(queueName));
332
+ _context7.prev = 11;
333
+ _context7.t0 = _context7["catch"](2);
334
+ return _context7.abrupt("return", this.getInfo(queueName));
304
335
  case 14:
305
- _context6.prev = 14;
306
- _context6.prev = 15;
307
- _context6.next = 18;
336
+ _context7.prev = 14;
337
+ _context7.prev = 15;
338
+ _context7.next = 18;
308
339
  return channel.close();
309
340
  case 18:
310
- _context6.next = 22;
341
+ _context7.next = 22;
311
342
  break;
312
343
  case 20:
313
- _context6.prev = 20;
314
- _context6.t1 = _context6["catch"](15);
344
+ _context7.prev = 20;
345
+ _context7.t1 = _context7["catch"](15);
315
346
  case 22:
316
- return _context6.finish(14);
347
+ return _context7.finish(14);
317
348
  case 23:
318
- _context6.next = 26;
349
+ _context7.next = 26;
319
350
  break;
320
351
  case 25:
321
- return _context6.abrupt("return", this.getInfo(queueName));
352
+ return _context7.abrupt("return", this.getInfo(queueName));
322
353
  case 26:
323
354
  case "end":
324
- return _context6.stop();
355
+ return _context7.stop();
325
356
  }
326
357
  }
327
- }, _callee6, this, [[2, 11, 14, 23], [15, 20]]);
358
+ }, _callee7, this, [[2, 11, 14, 23], [15, 20]]);
328
359
  }));
329
- function getInfo(_x3) {
360
+ function getInfo(_x4) {
330
361
  return _getInfo.apply(this, arguments);
331
362
  }
332
363
  return getInfo;
@@ -334,57 +365,57 @@ var RabbitMQAsync = /*#__PURE__*/function () {
334
365
  }, {
335
366
  key: "consume",
336
367
  value: function () {
337
- var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb) {
368
+ var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
338
369
  var callbackError,
339
370
  prefixQueueName,
340
371
  channel,
341
372
  messageQueue,
342
- _args8 = arguments;
343
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
373
+ _args9 = arguments;
374
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
344
375
  while (1) {
345
- switch (_context8.prev = _context8.next) {
376
+ switch (_context9.prev = _context9.next) {
346
377
  case 0:
347
- callbackError = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
378
+ callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
348
379
  prefixQueueName = this.parsePrefix(queueName);
349
380
  if (!this.connected) {
350
- _context8.next = 30;
381
+ _context9.next = 30;
351
382
  break;
352
383
  }
353
- _context8.prev = 3;
354
- _context8.next = 6;
384
+ _context9.prev = 3;
385
+ _context9.next = 6;
355
386
  return this.client.createChannel();
356
387
  case 6:
357
- channel = _context8.sent;
358
- _context8.next = 9;
388
+ channel = _context9.sent;
389
+ _context9.next = 9;
359
390
  return channel.assertQueue(prefixQueueName, {
360
391
  durable: true
361
392
  });
362
393
  case 9:
363
- _context8.next = 11;
394
+ _context9.next = 11;
364
395
  return channel.prefetch(1);
365
396
  case 11:
366
397
  messageQueue = this;
367
- _context8.next = 14;
398
+ _context9.next = 14;
368
399
  return new Promise(function (resolve, reject) {
369
400
  channel.consume(prefixQueueName, /*#__PURE__*/function () {
370
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(msg) {
401
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(msg) {
371
402
  var data, errString;
372
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
403
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
373
404
  while (1) {
374
- switch (_context7.prev = _context7.next) {
405
+ switch (_context8.prev = _context8.next) {
375
406
  case 0:
376
407
  if (!msg) {
377
- _context7.next = 55;
408
+ _context8.next = 55;
378
409
  break;
379
410
  }
380
411
  data = JSON.parse(msg.content.toString());
381
412
  if (!data) {
382
- _context7.next = 52;
413
+ _context8.next = 52;
383
414
  break;
384
415
  }
385
- _context7.prev = 3;
416
+ _context8.prev = 3;
386
417
  if (!msg.fields.redelivered) {
387
- _context7.next = 23;
418
+ _context8.next = 23;
388
419
  break;
389
420
  }
390
421
  if (!data.retry) {
@@ -392,143 +423,143 @@ var RabbitMQAsync = /*#__PURE__*/function () {
392
423
  }
393
424
  data.retry += 1;
394
425
  if (!(data.retry < 5)) {
395
- _context7.next = 17;
426
+ _context8.next = 17;
396
427
  break;
397
428
  }
398
429
  if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
399
- _context7.next = 13;
430
+ _context8.next = 13;
400
431
  break;
401
432
  }
402
- _context7.next = 11;
433
+ _context8.next = 11;
403
434
  return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
404
435
  case 11:
405
- _context7.next = 15;
436
+ _context8.next = 15;
406
437
  break;
407
438
  case 13:
408
- _context7.next = 15;
439
+ _context8.next = 15;
409
440
  return messageQueue.send(queueName, data);
410
441
  case 15:
411
- _context7.next = 19;
442
+ _context8.next = 19;
412
443
  break;
413
444
  case 17:
414
- _context7.next = 19;
445
+ _context8.next = 19;
415
446
  return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
416
447
  queueName: queueName,
417
448
  data: data,
418
449
  retry_time: new Date()
419
450
  });
420
451
  case 19:
421
- _context7.next = 21;
452
+ _context8.next = 21;
422
453
  return channel.ack(msg);
423
454
  case 21:
424
- _context7.next = 45;
455
+ _context8.next = 45;
425
456
  break;
426
457
  case 23:
427
- _context7.prev = 23;
428
- _context7.next = 26;
458
+ _context8.prev = 23;
459
+ _context8.next = 26;
429
460
  return cb(data);
430
461
  case 26:
431
- _context7.next = 28;
462
+ _context8.next = 28;
432
463
  return channel.ack(msg);
433
464
  case 28:
434
- _context7.next = 45;
465
+ _context8.next = 45;
435
466
  break;
436
467
  case 30:
437
- _context7.prev = 30;
438
- _context7.t0 = _context7["catch"](23);
439
- errString = _context7.t0.toString();
468
+ _context8.prev = 30;
469
+ _context8.t0 = _context8["catch"](23);
470
+ errString = _context8.t0.toString();
440
471
  if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
441
472
  return _lodash["default"].includes(errString, el);
442
473
  })) {
443
- _context7.next = 37;
474
+ _context8.next = 37;
444
475
  break;
445
476
  }
446
477
  reject(new Error(errString));
447
- _context7.next = 45;
478
+ _context8.next = 45;
448
479
  break;
449
480
  case 37:
450
481
  if (callbackError) {
451
- callbackError(prefixQueueName, _context7.t0);
482
+ callbackError(prefixQueueName, _context8.t0);
452
483
  }
453
484
  if (!data.noRetry) {
454
- _context7.next = 43;
485
+ _context8.next = 43;
455
486
  break;
456
487
  }
457
- _context7.next = 41;
488
+ _context8.next = 41;
458
489
  return channel.ack(msg);
459
490
  case 41:
460
- _context7.next = 45;
491
+ _context8.next = 45;
461
492
  break;
462
493
  case 43:
463
- _context7.next = 45;
494
+ _context8.next = 45;
464
495
  return channel.nack(msg);
465
496
  case 45:
466
- _context7.next = 50;
497
+ _context8.next = 50;
467
498
  break;
468
499
  case 47:
469
- _context7.prev = 47;
470
- _context7.t1 = _context7["catch"](3);
471
- reject(_context7.t1);
500
+ _context8.prev = 47;
501
+ _context8.t1 = _context8["catch"](3);
502
+ reject(_context8.t1);
472
503
  case 50:
473
- _context7.next = 53;
504
+ _context8.next = 53;
474
505
  break;
475
506
  case 52:
476
507
  channel.ack(msg);
477
508
  case 53:
478
- _context7.next = 56;
509
+ _context8.next = 56;
479
510
  break;
480
511
  case 55:
481
512
  reject(new Error('msg null'));
482
513
  case 56:
483
514
  case "end":
484
- return _context7.stop();
515
+ return _context8.stop();
485
516
  }
486
517
  }
487
- }, _callee7, null, [[3, 47], [23, 30]]);
518
+ }, _callee8, null, [[3, 47], [23, 30]]);
488
519
  }));
489
- return function (_x6) {
520
+ return function (_x7) {
490
521
  return _ref.apply(this, arguments);
491
522
  };
492
523
  }());
493
524
  });
494
525
  case 14:
495
- _context8.next = 28;
526
+ _context9.next = 28;
496
527
  break;
497
528
  case 16:
498
- _context8.prev = 16;
499
- _context8.t0 = _context8["catch"](3);
500
- _context8.prev = 18;
501
- _context8.next = 21;
529
+ _context9.prev = 16;
530
+ _context9.t0 = _context9["catch"](3);
531
+ _context9.prev = 18;
532
+ _context9.next = 21;
502
533
  return channel.close();
503
534
  case 21:
504
- _context8.next = 25;
535
+ _context9.next = 25;
505
536
  break;
506
537
  case 23:
507
- _context8.prev = 23;
508
- _context8.t1 = _context8["catch"](18);
538
+ _context9.prev = 23;
539
+ _context9.t1 = _context9["catch"](18);
509
540
  case 25:
510
- _context8.next = 27;
541
+ _context9.next = 27;
511
542
  return (0, _util.timeout)(5000);
512
543
  case 27:
513
- return _context8.abrupt("return", this.consume(queueName, cb, callbackError));
544
+ return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
514
545
  case 28:
515
- _context8.next = 33;
546
+ _context9.next = 33;
516
547
  break;
517
548
  case 30:
518
- _context8.next = 32;
549
+ _context9.next = 32;
519
550
  return (0, _util.timeout)(5000);
520
551
  case 32:
521
- return _context8.abrupt("return", this.consume(queueName, cb, callbackError));
552
+ return _context9.abrupt("return", this.consume(queueName, cb, callbackError));
522
553
  case 33:
523
- return _context8.abrupt("return", true);
554
+ return _context9.abrupt("return", true);
524
555
  case 34:
525
556
  case "end":
526
- return _context8.stop();
557
+ return _context9.stop();
527
558
  }
528
559
  }
529
- }, _callee8, this, [[3, 16], [18, 23]]);
560
+ }, _callee9, this, [[3, 16], [18, 23]]);
530
561
  }));
531
- function consume(_x4, _x5) {
562
+ function consume(_x5, _x6) {
532
563
  return _consume.apply(this, arguments);
533
564
  }
534
565
  return consume;
@@ -536,20 +567,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
536
567
  }, {
537
568
  key: "selfReceiving",
538
569
  value: function () {
539
- var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb, callbackError) {
540
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
570
+ var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(queueName, cb, callbackError) {
571
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
541
572
  while (1) {
542
- switch (_context9.prev = _context9.next) {
573
+ switch (_context10.prev = _context10.next) {
543
574
  case 0:
544
575
  this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
545
576
  case 1:
546
577
  case "end":
547
- return _context9.stop();
578
+ return _context10.stop();
548
579
  }
549
580
  }
550
- }, _callee9, this);
581
+ }, _callee10, this);
551
582
  }));
552
- function selfReceiving(_x7, _x8, _x9) {
583
+ function selfReceiving(_x8, _x9, _x10) {
553
584
  return _selfReceiving.apply(this, arguments);
554
585
  }
555
586
  return selfReceiving;
@@ -557,26 +588,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
557
588
  }, {
558
589
  key: "receiving",
559
590
  value: function () {
560
- var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(queueName, cb) {
591
+ var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(queueName, cb) {
561
592
  var callbackError,
562
- _args10 = arguments;
563
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
593
+ _args11 = arguments;
594
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
564
595
  while (1) {
565
- switch (_context10.prev = _context10.next) {
596
+ switch (_context11.prev = _context11.next) {
566
597
  case 0:
567
- callbackError = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : null;
598
+ callbackError = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : null;
568
599
  this.consume(queueName, cb, callbackError);
569
600
  if (this.worker) {
570
601
  this.selfReceiving(queueName, cb, callbackError);
571
602
  }
572
603
  case 3:
573
604
  case "end":
574
- return _context10.stop();
605
+ return _context11.stop();
575
606
  }
576
607
  }
577
- }, _callee10, this);
608
+ }, _callee11, this);
578
609
  }));
579
- function receiving(_x10, _x11) {
610
+ function receiving(_x11, _x12) {
580
611
  return _receiving.apply(this, arguments);
581
612
  }
582
613
  return receiving;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.163",
3
+ "version": "1.0.165",
4
4
  "description": "",
5
- "main": "./lib/index.js",
6
- "module": "./src/index.js",
7
- "scripts": {
8
- "build": "babel src --delete-dir-on-start -d lib"
9
- },
10
5
  "keywords": [
11
6
  "toda",
12
7
  "nodejs",
13
8
  "rabbitmq",
14
9
  "rabbitmq async"
15
10
  ],
16
- "author": "toda <sp.azsolution.net@gmail.com>",
17
11
  "license": "MIT",
12
+ "author": "toda <sp.azsolution.net@gmail.com>",
13
+ "main": "./lib/index.js",
14
+ "module": "./src/index.js",
15
+ "scripts": {
16
+ "build": "babel src --delete-dir-on-start -d lib"
17
+ },
18
18
  "dependencies": {
19
19
  "@azteam/util": "1.0.29",
20
20
  "amqplib": "0.8.0",
@@ -72,7 +72,7 @@ class RabbitMQAsync {
72
72
  return name;
73
73
  }
74
74
 
75
- async send(queueName, msg = {}, limit = false) {
75
+ async send(queueName, msg = {}, limit = 0) {
76
76
  const prefixQueueName = this.parsePrefix(queueName);
77
77
 
78
78
  if (this.connected) {
@@ -83,7 +83,7 @@ class RabbitMQAsync {
83
83
  durable: true,
84
84
  });
85
85
 
86
- if (!limit || queueInfo.messageCount < limit) {
86
+ if (limit === 0 || queueInfo.messageCount < limit) {
87
87
  await channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify(msg)), {
88
88
  persistent: true,
89
89
  });
@@ -104,8 +104,12 @@ class RabbitMQAsync {
104
104
  }
105
105
  }
106
106
 
107
- async sendNoRetry(queueName, msg = {}, limit = false) {
108
- this.send(queueName, msg, limit);
107
+ async selfSend(queueName, msg = {}, limit = 0) {
108
+ this.send(`${this.serverIp}_${queueName}`, msg, limit);
109
+ }
110
+
111
+ async sendNoRetry(queueName, msg = {}, limit = 0) {
112
+ this.send(queueName, {...msg, noRetry: true}, limit);
109
113
  }
110
114
 
111
115
  async getInfo(queueName) {