@azteam/rabbitmq-async 1.0.167 → 1.0.168
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 +150 -245
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +13 -28
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -162,6 +162,11 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
162
162
|
}, {
|
|
163
163
|
key: "parsePrefix",
|
|
164
164
|
value: function parsePrefix(name) {
|
|
165
|
+
var self = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
166
|
+
if (self) {
|
|
167
|
+
// eslint-disable-next-line no-param-reassign
|
|
168
|
+
name = "".concat(this.serverIp, "_").concat(name);
|
|
169
|
+
}
|
|
165
170
|
if (this.prefix) {
|
|
166
171
|
return "".concat(this.prefix, ":").concat(name);
|
|
167
172
|
}
|
|
@@ -183,7 +188,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
183
188
|
case 0:
|
|
184
189
|
msg = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
|
|
185
190
|
limit = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 0;
|
|
186
|
-
prefixQueueName = this.parsePrefix(queueName);
|
|
191
|
+
prefixQueueName = this.parsePrefix(queueName, msg.self);
|
|
187
192
|
if (!this.connected) {
|
|
188
193
|
_context4.next = 33;
|
|
189
194
|
break;
|
|
@@ -204,7 +209,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
204
209
|
break;
|
|
205
210
|
}
|
|
206
211
|
_context4.next = 14;
|
|
207
|
-
return channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify(
|
|
212
|
+
return channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify(_objectSpread({
|
|
213
|
+
retry: 5
|
|
214
|
+
}, msg))), {
|
|
208
215
|
persistent: true
|
|
209
216
|
});
|
|
210
217
|
case 14:
|
|
@@ -250,365 +257,263 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
250
257
|
return send;
|
|
251
258
|
}()
|
|
252
259
|
}, {
|
|
253
|
-
key: "
|
|
260
|
+
key: "getInfo",
|
|
254
261
|
value: function () {
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
|
|
262
|
+
var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(queueName) {
|
|
263
|
+
var self,
|
|
264
|
+
prefixQueueName,
|
|
265
|
+
channel,
|
|
258
266
|
_args5 = arguments;
|
|
259
267
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
260
268
|
while (1) {
|
|
261
269
|
switch (_context5.prev = _context5.next) {
|
|
262
270
|
case 0:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
this.send("".concat(this.serverIp, "_").concat(queueName), msg, limit);
|
|
266
|
-
case 3:
|
|
267
|
-
case "end":
|
|
268
|
-
return _context5.stop();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}, _callee5, this);
|
|
272
|
-
}));
|
|
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) {
|
|
302
|
-
return _sendNoRetry.apply(this, arguments);
|
|
303
|
-
}
|
|
304
|
-
return sendNoRetry;
|
|
305
|
-
}()
|
|
306
|
-
}, {
|
|
307
|
-
key: "selfSendNoRetry",
|
|
308
|
-
value: function () {
|
|
309
|
-
var _selfSendNoRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName) {
|
|
310
|
-
var msg,
|
|
311
|
-
limit,
|
|
312
|
-
_args7 = arguments;
|
|
313
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
314
|
-
while (1) {
|
|
315
|
-
switch (_context7.prev = _context7.next) {
|
|
316
|
-
case 0:
|
|
317
|
-
msg = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
|
|
318
|
-
limit = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : 0;
|
|
319
|
-
this.selfSend(queueName, _objectSpread(_objectSpread({}, msg), {}, {
|
|
320
|
-
noRetry: true
|
|
321
|
-
}), limit);
|
|
322
|
-
case 3:
|
|
323
|
-
case "end":
|
|
324
|
-
return _context7.stop();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}, _callee7, this);
|
|
328
|
-
}));
|
|
329
|
-
function selfSendNoRetry(_x4) {
|
|
330
|
-
return _selfSendNoRetry.apply(this, arguments);
|
|
331
|
-
}
|
|
332
|
-
return selfSendNoRetry;
|
|
333
|
-
}()
|
|
334
|
-
}, {
|
|
335
|
-
key: "getInfo",
|
|
336
|
-
value: function () {
|
|
337
|
-
var _getInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName) {
|
|
338
|
-
var prefixQueueName, channel;
|
|
339
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
340
|
-
while (1) {
|
|
341
|
-
switch (_context8.prev = _context8.next) {
|
|
342
|
-
case 0:
|
|
343
|
-
prefixQueueName = this.parsePrefix(queueName);
|
|
271
|
+
self = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : false;
|
|
272
|
+
prefixQueueName = this.parsePrefix(queueName, self);
|
|
344
273
|
if (!this.connected) {
|
|
345
|
-
|
|
274
|
+
_context5.next = 26;
|
|
346
275
|
break;
|
|
347
276
|
}
|
|
348
|
-
|
|
349
|
-
|
|
277
|
+
_context5.prev = 3;
|
|
278
|
+
_context5.next = 6;
|
|
350
279
|
return this.client.createChannel();
|
|
351
|
-
case
|
|
352
|
-
channel =
|
|
353
|
-
|
|
280
|
+
case 6:
|
|
281
|
+
channel = _context5.sent;
|
|
282
|
+
_context5.next = 9;
|
|
354
283
|
return channel.assertQueue(prefixQueueName, {
|
|
355
284
|
durable: true
|
|
356
285
|
});
|
|
357
|
-
case
|
|
358
|
-
return
|
|
359
|
-
case
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return
|
|
363
|
-
case
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
286
|
+
case 9:
|
|
287
|
+
return _context5.abrupt("return", _context5.sent);
|
|
288
|
+
case 12:
|
|
289
|
+
_context5.prev = 12;
|
|
290
|
+
_context5.t0 = _context5["catch"](3);
|
|
291
|
+
return _context5.abrupt("return", this.getInfo(queueName));
|
|
292
|
+
case 15:
|
|
293
|
+
_context5.prev = 15;
|
|
294
|
+
_context5.prev = 16;
|
|
295
|
+
_context5.next = 19;
|
|
367
296
|
return channel.close();
|
|
368
|
-
case
|
|
369
|
-
|
|
297
|
+
case 19:
|
|
298
|
+
_context5.next = 23;
|
|
370
299
|
break;
|
|
371
|
-
case
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
case 22:
|
|
375
|
-
return _context8.finish(14);
|
|
300
|
+
case 21:
|
|
301
|
+
_context5.prev = 21;
|
|
302
|
+
_context5.t1 = _context5["catch"](16);
|
|
376
303
|
case 23:
|
|
377
|
-
|
|
304
|
+
return _context5.finish(15);
|
|
305
|
+
case 24:
|
|
306
|
+
_context5.next = 27;
|
|
378
307
|
break;
|
|
379
|
-
case 25:
|
|
380
|
-
return _context8.abrupt("return", this.getInfo(queueName));
|
|
381
308
|
case 26:
|
|
309
|
+
return _context5.abrupt("return", this.getInfo(queueName));
|
|
310
|
+
case 27:
|
|
382
311
|
case "end":
|
|
383
|
-
return
|
|
312
|
+
return _context5.stop();
|
|
384
313
|
}
|
|
385
314
|
}
|
|
386
|
-
},
|
|
315
|
+
}, _callee5, this, [[3, 12, 15, 24], [16, 21]]);
|
|
387
316
|
}));
|
|
388
|
-
function getInfo(
|
|
317
|
+
function getInfo(_x2) {
|
|
389
318
|
return _getInfo.apply(this, arguments);
|
|
390
319
|
}
|
|
391
320
|
return getInfo;
|
|
392
321
|
}()
|
|
393
|
-
}, {
|
|
394
|
-
key: "getSelfInfo",
|
|
395
|
-
value: function () {
|
|
396
|
-
var _getSelfInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName) {
|
|
397
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
398
|
-
while (1) {
|
|
399
|
-
switch (_context9.prev = _context9.next) {
|
|
400
|
-
case 0:
|
|
401
|
-
return _context9.abrupt("return", this.getInfo("".concat(this.serverIp, "_").concat(queueName)));
|
|
402
|
-
case 1:
|
|
403
|
-
case "end":
|
|
404
|
-
return _context9.stop();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}, _callee9, this);
|
|
408
|
-
}));
|
|
409
|
-
function getSelfInfo(_x6) {
|
|
410
|
-
return _getSelfInfo.apply(this, arguments);
|
|
411
|
-
}
|
|
412
|
-
return getSelfInfo;
|
|
413
|
-
}()
|
|
414
322
|
}, {
|
|
415
323
|
key: "consume",
|
|
416
324
|
value: function () {
|
|
417
|
-
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
325
|
+
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, cb) {
|
|
418
326
|
var callbackError,
|
|
419
327
|
prefixQueueName,
|
|
420
328
|
channel,
|
|
421
329
|
messageQueue,
|
|
422
|
-
|
|
423
|
-
return _regeneratorRuntime().wrap(function
|
|
330
|
+
_args7 = arguments;
|
|
331
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
424
332
|
while (1) {
|
|
425
|
-
switch (
|
|
333
|
+
switch (_context7.prev = _context7.next) {
|
|
426
334
|
case 0:
|
|
427
|
-
callbackError =
|
|
335
|
+
callbackError = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
|
|
428
336
|
prefixQueueName = this.parsePrefix(queueName);
|
|
429
337
|
if (!this.connected) {
|
|
430
|
-
|
|
338
|
+
_context7.next = 30;
|
|
431
339
|
break;
|
|
432
340
|
}
|
|
433
|
-
|
|
434
|
-
|
|
341
|
+
_context7.prev = 3;
|
|
342
|
+
_context7.next = 6;
|
|
435
343
|
return this.client.createChannel();
|
|
436
344
|
case 6:
|
|
437
|
-
channel =
|
|
438
|
-
|
|
345
|
+
channel = _context7.sent;
|
|
346
|
+
_context7.next = 9;
|
|
439
347
|
return channel.assertQueue(prefixQueueName, {
|
|
440
348
|
durable: true
|
|
441
349
|
});
|
|
442
350
|
case 9:
|
|
443
|
-
|
|
351
|
+
_context7.next = 11;
|
|
444
352
|
return channel.prefetch(1);
|
|
445
353
|
case 11:
|
|
446
354
|
messageQueue = this;
|
|
447
|
-
|
|
355
|
+
_context7.next = 14;
|
|
448
356
|
return new Promise(function (resolve, reject) {
|
|
449
357
|
channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
450
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
358
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(msg) {
|
|
451
359
|
var data, errString;
|
|
452
|
-
return _regeneratorRuntime().wrap(function
|
|
360
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
453
361
|
while (1) {
|
|
454
|
-
switch (
|
|
362
|
+
switch (_context6.prev = _context6.next) {
|
|
455
363
|
case 0:
|
|
456
364
|
if (!msg) {
|
|
457
|
-
|
|
365
|
+
_context6.next = 54;
|
|
458
366
|
break;
|
|
459
367
|
}
|
|
460
368
|
data = JSON.parse(msg.content.toString());
|
|
461
369
|
if (!data) {
|
|
462
|
-
|
|
370
|
+
_context6.next = 51;
|
|
463
371
|
break;
|
|
464
372
|
}
|
|
465
|
-
|
|
373
|
+
_context6.prev = 3;
|
|
466
374
|
if (!msg.fields.redelivered) {
|
|
467
|
-
|
|
375
|
+
_context6.next = 22;
|
|
468
376
|
break;
|
|
469
377
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
data.retry += 1;
|
|
474
|
-
if (!(data.retry < 5)) {
|
|
475
|
-
_context10.next = 17;
|
|
378
|
+
data.retry -= 1;
|
|
379
|
+
if (!(data.retry > 0)) {
|
|
380
|
+
_context6.next = 16;
|
|
476
381
|
break;
|
|
477
382
|
}
|
|
478
383
|
if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
|
|
479
|
-
|
|
384
|
+
_context6.next = 12;
|
|
480
385
|
break;
|
|
481
386
|
}
|
|
482
|
-
|
|
387
|
+
_context6.next = 10;
|
|
483
388
|
return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
|
|
484
|
-
case
|
|
485
|
-
|
|
389
|
+
case 10:
|
|
390
|
+
_context6.next = 14;
|
|
486
391
|
break;
|
|
487
|
-
case
|
|
488
|
-
|
|
392
|
+
case 12:
|
|
393
|
+
_context6.next = 14;
|
|
489
394
|
return messageQueue.send(queueName, data);
|
|
490
|
-
case
|
|
491
|
-
|
|
395
|
+
case 14:
|
|
396
|
+
_context6.next = 18;
|
|
492
397
|
break;
|
|
493
|
-
case
|
|
494
|
-
|
|
398
|
+
case 16:
|
|
399
|
+
_context6.next = 18;
|
|
495
400
|
return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
496
401
|
queueName: queueName,
|
|
497
402
|
data: data,
|
|
498
403
|
retry_time: new Date()
|
|
499
404
|
});
|
|
500
|
-
case
|
|
501
|
-
|
|
405
|
+
case 18:
|
|
406
|
+
_context6.next = 20;
|
|
502
407
|
return channel.ack(msg);
|
|
503
|
-
case
|
|
504
|
-
|
|
408
|
+
case 20:
|
|
409
|
+
_context6.next = 44;
|
|
505
410
|
break;
|
|
506
|
-
case
|
|
507
|
-
|
|
508
|
-
|
|
411
|
+
case 22:
|
|
412
|
+
_context6.prev = 22;
|
|
413
|
+
_context6.next = 25;
|
|
509
414
|
return cb(data);
|
|
510
|
-
case
|
|
511
|
-
|
|
415
|
+
case 25:
|
|
416
|
+
_context6.next = 27;
|
|
512
417
|
return channel.ack(msg);
|
|
513
|
-
case
|
|
514
|
-
|
|
418
|
+
case 27:
|
|
419
|
+
_context6.next = 44;
|
|
515
420
|
break;
|
|
516
|
-
case
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
errString =
|
|
421
|
+
case 29:
|
|
422
|
+
_context6.prev = 29;
|
|
423
|
+
_context6.t0 = _context6["catch"](22);
|
|
424
|
+
errString = _context6.t0.toString();
|
|
520
425
|
if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
|
|
521
426
|
return _lodash["default"].includes(errString, el);
|
|
522
427
|
})) {
|
|
523
|
-
|
|
428
|
+
_context6.next = 36;
|
|
524
429
|
break;
|
|
525
430
|
}
|
|
526
431
|
reject(new Error(errString));
|
|
527
|
-
|
|
432
|
+
_context6.next = 44;
|
|
528
433
|
break;
|
|
529
|
-
case
|
|
434
|
+
case 36:
|
|
530
435
|
if (callbackError) {
|
|
531
|
-
callbackError(prefixQueueName,
|
|
436
|
+
callbackError(prefixQueueName, _context6.t0);
|
|
532
437
|
}
|
|
533
|
-
if (!data.
|
|
534
|
-
|
|
438
|
+
if (!(data.retry <= 0)) {
|
|
439
|
+
_context6.next = 42;
|
|
535
440
|
break;
|
|
536
441
|
}
|
|
537
|
-
|
|
442
|
+
_context6.next = 40;
|
|
538
443
|
return channel.ack(msg);
|
|
539
|
-
case
|
|
540
|
-
|
|
444
|
+
case 40:
|
|
445
|
+
_context6.next = 44;
|
|
541
446
|
break;
|
|
542
|
-
case
|
|
543
|
-
|
|
447
|
+
case 42:
|
|
448
|
+
_context6.next = 44;
|
|
544
449
|
return channel.nack(msg);
|
|
545
|
-
case
|
|
546
|
-
|
|
450
|
+
case 44:
|
|
451
|
+
_context6.next = 49;
|
|
547
452
|
break;
|
|
548
|
-
case
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
reject(
|
|
552
|
-
case
|
|
553
|
-
|
|
453
|
+
case 46:
|
|
454
|
+
_context6.prev = 46;
|
|
455
|
+
_context6.t1 = _context6["catch"](3);
|
|
456
|
+
reject(_context6.t1);
|
|
457
|
+
case 49:
|
|
458
|
+
_context6.next = 52;
|
|
554
459
|
break;
|
|
555
|
-
case
|
|
460
|
+
case 51:
|
|
556
461
|
channel.ack(msg);
|
|
557
|
-
case
|
|
558
|
-
|
|
462
|
+
case 52:
|
|
463
|
+
_context6.next = 55;
|
|
559
464
|
break;
|
|
560
|
-
case
|
|
465
|
+
case 54:
|
|
561
466
|
reject(new Error('msg null'));
|
|
562
|
-
case
|
|
467
|
+
case 55:
|
|
563
468
|
case "end":
|
|
564
|
-
return
|
|
469
|
+
return _context6.stop();
|
|
565
470
|
}
|
|
566
471
|
}
|
|
567
|
-
},
|
|
472
|
+
}, _callee6, null, [[3, 46], [22, 29]]);
|
|
568
473
|
}));
|
|
569
|
-
return function (
|
|
474
|
+
return function (_x5) {
|
|
570
475
|
return _ref.apply(this, arguments);
|
|
571
476
|
};
|
|
572
477
|
}());
|
|
573
478
|
});
|
|
574
479
|
case 14:
|
|
575
|
-
|
|
480
|
+
_context7.next = 28;
|
|
576
481
|
break;
|
|
577
482
|
case 16:
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
483
|
+
_context7.prev = 16;
|
|
484
|
+
_context7.t0 = _context7["catch"](3);
|
|
485
|
+
_context7.prev = 18;
|
|
486
|
+
_context7.next = 21;
|
|
582
487
|
return channel.close();
|
|
583
488
|
case 21:
|
|
584
|
-
|
|
489
|
+
_context7.next = 25;
|
|
585
490
|
break;
|
|
586
491
|
case 23:
|
|
587
|
-
|
|
588
|
-
|
|
492
|
+
_context7.prev = 23;
|
|
493
|
+
_context7.t1 = _context7["catch"](18);
|
|
589
494
|
case 25:
|
|
590
|
-
|
|
495
|
+
_context7.next = 27;
|
|
591
496
|
return (0, _util.timeout)(5000);
|
|
592
497
|
case 27:
|
|
593
|
-
return
|
|
498
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
594
499
|
case 28:
|
|
595
|
-
|
|
500
|
+
_context7.next = 33;
|
|
596
501
|
break;
|
|
597
502
|
case 30:
|
|
598
|
-
|
|
503
|
+
_context7.next = 32;
|
|
599
504
|
return (0, _util.timeout)(5000);
|
|
600
505
|
case 32:
|
|
601
|
-
return
|
|
506
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
602
507
|
case 33:
|
|
603
|
-
return
|
|
508
|
+
return _context7.abrupt("return", true);
|
|
604
509
|
case 34:
|
|
605
510
|
case "end":
|
|
606
|
-
return
|
|
511
|
+
return _context7.stop();
|
|
607
512
|
}
|
|
608
513
|
}
|
|
609
|
-
},
|
|
514
|
+
}, _callee7, this, [[3, 16], [18, 23]]);
|
|
610
515
|
}));
|
|
611
|
-
function consume(
|
|
516
|
+
function consume(_x3, _x4) {
|
|
612
517
|
return _consume.apply(this, arguments);
|
|
613
518
|
}
|
|
614
519
|
return consume;
|
|
@@ -616,20 +521,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
616
521
|
}, {
|
|
617
522
|
key: "selfReceiving",
|
|
618
523
|
value: function () {
|
|
619
|
-
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
620
|
-
return _regeneratorRuntime().wrap(function
|
|
524
|
+
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb, callbackError) {
|
|
525
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
621
526
|
while (1) {
|
|
622
|
-
switch (
|
|
527
|
+
switch (_context8.prev = _context8.next) {
|
|
623
528
|
case 0:
|
|
624
529
|
this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
|
|
625
530
|
case 1:
|
|
626
531
|
case "end":
|
|
627
|
-
return
|
|
532
|
+
return _context8.stop();
|
|
628
533
|
}
|
|
629
534
|
}
|
|
630
|
-
},
|
|
535
|
+
}, _callee8, this);
|
|
631
536
|
}));
|
|
632
|
-
function selfReceiving(
|
|
537
|
+
function selfReceiving(_x6, _x7, _x8) {
|
|
633
538
|
return _selfReceiving.apply(this, arguments);
|
|
634
539
|
}
|
|
635
540
|
return selfReceiving;
|
|
@@ -637,26 +542,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
637
542
|
}, {
|
|
638
543
|
key: "receiving",
|
|
639
544
|
value: function () {
|
|
640
|
-
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
545
|
+
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
|
|
641
546
|
var callbackError,
|
|
642
|
-
|
|
643
|
-
return _regeneratorRuntime().wrap(function
|
|
547
|
+
_args9 = arguments;
|
|
548
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
644
549
|
while (1) {
|
|
645
|
-
switch (
|
|
550
|
+
switch (_context9.prev = _context9.next) {
|
|
646
551
|
case 0:
|
|
647
|
-
callbackError =
|
|
552
|
+
callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
|
|
648
553
|
this.consume(queueName, cb, callbackError);
|
|
649
554
|
if (this.worker) {
|
|
650
555
|
this.selfReceiving(queueName, cb, callbackError);
|
|
651
556
|
}
|
|
652
557
|
case 3:
|
|
653
558
|
case "end":
|
|
654
|
-
return
|
|
559
|
+
return _context9.stop();
|
|
655
560
|
}
|
|
656
561
|
}
|
|
657
|
-
},
|
|
562
|
+
}, _callee9, this);
|
|
658
563
|
}));
|
|
659
|
-
function receiving(
|
|
564
|
+
function receiving(_x9, _x10) {
|
|
660
565
|
return _receiving.apply(this, arguments);
|
|
661
566
|
}
|
|
662
567
|
return receiving;
|
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -65,7 +65,12 @@ class RabbitMQAsync {
|
|
|
65
65
|
this.client.close();
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
parsePrefix(name) {
|
|
68
|
+
parsePrefix(name, self = false) {
|
|
69
|
+
if (self) {
|
|
70
|
+
// eslint-disable-next-line no-param-reassign
|
|
71
|
+
name = `${this.serverIp}_${name}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
if (this.prefix) {
|
|
70
75
|
return `${this.prefix}:${name}`;
|
|
71
76
|
}
|
|
@@ -73,7 +78,7 @@ class RabbitMQAsync {
|
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
async send(queueName, msg = {}, limit = 0) {
|
|
76
|
-
const prefixQueueName = this.parsePrefix(queueName);
|
|
81
|
+
const prefixQueueName = this.parsePrefix(queueName, msg.self);
|
|
77
82
|
|
|
78
83
|
if (this.connected) {
|
|
79
84
|
let channel;
|
|
@@ -84,7 +89,7 @@ class RabbitMQAsync {
|
|
|
84
89
|
});
|
|
85
90
|
|
|
86
91
|
if (limit === 0 || queueInfo.messageCount < limit) {
|
|
87
|
-
await channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify(msg)), {
|
|
92
|
+
await channel.sendToQueue(prefixQueueName, Buffer.from(JSON.stringify({retry: 5, ...msg})), {
|
|
88
93
|
persistent: true,
|
|
89
94
|
});
|
|
90
95
|
}
|
|
@@ -104,20 +109,8 @@ class RabbitMQAsync {
|
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
|
-
async
|
|
108
|
-
this.
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async sendNoRetry(queueName, msg = {}, limit = 0) {
|
|
112
|
-
this.send(queueName, {...msg, noRetry: true}, limit);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async selfSendNoRetry(queueName, msg = {}, limit = 0) {
|
|
116
|
-
this.selfSend(queueName, {...msg, noRetry: true}, limit);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async getInfo(queueName) {
|
|
120
|
-
const prefixQueueName = this.parsePrefix(queueName);
|
|
112
|
+
async getInfo(queueName, self = false) {
|
|
113
|
+
const prefixQueueName = this.parsePrefix(queueName, self);
|
|
121
114
|
|
|
122
115
|
if (this.connected) {
|
|
123
116
|
let channel;
|
|
@@ -138,10 +131,6 @@ class RabbitMQAsync {
|
|
|
138
131
|
}
|
|
139
132
|
}
|
|
140
133
|
|
|
141
|
-
async getSelfInfo(queueName) {
|
|
142
|
-
return this.getInfo(`${this.serverIp}_${queueName}`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
134
|
async consume(queueName, cb, callbackError = null) {
|
|
146
135
|
const prefixQueueName = this.parsePrefix(queueName);
|
|
147
136
|
|
|
@@ -166,12 +155,8 @@ class RabbitMQAsync {
|
|
|
166
155
|
if (data) {
|
|
167
156
|
try {
|
|
168
157
|
if (msg.fields.redelivered) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
data.retry += 1;
|
|
173
|
-
|
|
174
|
-
if (data.retry < 5) {
|
|
158
|
+
data.retry -= 1;
|
|
159
|
+
if (data.retry > 0) {
|
|
175
160
|
if (messageQueue.worker && !queueName.startsWith(messageQueue.serverIp)) {
|
|
176
161
|
await messageQueue.send(`${messageQueue.serverIp}_${queueName}`, data);
|
|
177
162
|
} else {
|
|
@@ -198,7 +183,7 @@ class RabbitMQAsync {
|
|
|
198
183
|
if (callbackError) {
|
|
199
184
|
callbackError(prefixQueueName, err);
|
|
200
185
|
}
|
|
201
|
-
if (data.
|
|
186
|
+
if (data.retry <= 0) {
|
|
202
187
|
await channel.ack(msg);
|
|
203
188
|
} else {
|
|
204
189
|
await channel.nack(msg);
|