@azteam/rabbitmq-async 1.0.167 → 1.0.169
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 +145 -250
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +14 -33
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,253 @@ 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 = 49;
|
|
458
366
|
break;
|
|
459
367
|
}
|
|
460
368
|
data = JSON.parse(msg.content.toString());
|
|
461
369
|
if (!data) {
|
|
462
|
-
|
|
370
|
+
_context6.next = 46;
|
|
463
371
|
break;
|
|
464
372
|
}
|
|
465
|
-
|
|
373
|
+
_context6.prev = 3;
|
|
466
374
|
if (!msg.fields.redelivered) {
|
|
467
|
-
|
|
375
|
+
_context6.next = 17;
|
|
468
376
|
break;
|
|
469
377
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
data.retry += 1;
|
|
474
|
-
if (!(data.retry < 5)) {
|
|
475
|
-
_context10.next = 17;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
|
|
479
|
-
_context10.next = 13;
|
|
378
|
+
data.retry -= 1;
|
|
379
|
+
if (!(data.retry > 0)) {
|
|
380
|
+
_context6.next = 11;
|
|
480
381
|
break;
|
|
481
382
|
}
|
|
482
|
-
|
|
483
|
-
return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
|
|
484
|
-
case 11:
|
|
485
|
-
_context10.next = 15;
|
|
486
|
-
break;
|
|
487
|
-
case 13:
|
|
488
|
-
_context10.next = 15;
|
|
383
|
+
_context6.next = 9;
|
|
489
384
|
return messageQueue.send(queueName, data);
|
|
490
|
-
case
|
|
491
|
-
|
|
385
|
+
case 9:
|
|
386
|
+
_context6.next = 13;
|
|
492
387
|
break;
|
|
493
|
-
case
|
|
494
|
-
|
|
388
|
+
case 11:
|
|
389
|
+
_context6.next = 13;
|
|
495
390
|
return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
496
391
|
queueName: queueName,
|
|
497
392
|
data: data,
|
|
498
393
|
retry_time: new Date()
|
|
499
394
|
});
|
|
500
|
-
case
|
|
501
|
-
|
|
395
|
+
case 13:
|
|
396
|
+
_context6.next = 15;
|
|
502
397
|
return channel.ack(msg);
|
|
503
|
-
case
|
|
504
|
-
|
|
398
|
+
case 15:
|
|
399
|
+
_context6.next = 39;
|
|
505
400
|
break;
|
|
506
|
-
case
|
|
507
|
-
|
|
508
|
-
|
|
401
|
+
case 17:
|
|
402
|
+
_context6.prev = 17;
|
|
403
|
+
_context6.next = 20;
|
|
509
404
|
return cb(data);
|
|
510
|
-
case
|
|
511
|
-
|
|
405
|
+
case 20:
|
|
406
|
+
_context6.next = 22;
|
|
512
407
|
return channel.ack(msg);
|
|
513
|
-
case
|
|
514
|
-
|
|
408
|
+
case 22:
|
|
409
|
+
_context6.next = 39;
|
|
515
410
|
break;
|
|
516
|
-
case
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
errString =
|
|
411
|
+
case 24:
|
|
412
|
+
_context6.prev = 24;
|
|
413
|
+
_context6.t0 = _context6["catch"](17);
|
|
414
|
+
errString = _context6.t0.toString();
|
|
520
415
|
if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
|
|
521
416
|
return _lodash["default"].includes(errString, el);
|
|
522
417
|
})) {
|
|
523
|
-
|
|
418
|
+
_context6.next = 31;
|
|
524
419
|
break;
|
|
525
420
|
}
|
|
526
421
|
reject(new Error(errString));
|
|
527
|
-
|
|
422
|
+
_context6.next = 39;
|
|
528
423
|
break;
|
|
529
|
-
case
|
|
424
|
+
case 31:
|
|
530
425
|
if (callbackError) {
|
|
531
|
-
callbackError(prefixQueueName,
|
|
426
|
+
callbackError(prefixQueueName, _context6.t0);
|
|
532
427
|
}
|
|
533
|
-
if (!data.
|
|
534
|
-
|
|
428
|
+
if (!(data.retry <= 0)) {
|
|
429
|
+
_context6.next = 37;
|
|
535
430
|
break;
|
|
536
431
|
}
|
|
537
|
-
|
|
432
|
+
_context6.next = 35;
|
|
538
433
|
return channel.ack(msg);
|
|
539
|
-
case
|
|
540
|
-
|
|
434
|
+
case 35:
|
|
435
|
+
_context6.next = 39;
|
|
541
436
|
break;
|
|
542
|
-
case
|
|
543
|
-
|
|
437
|
+
case 37:
|
|
438
|
+
_context6.next = 39;
|
|
544
439
|
return channel.nack(msg);
|
|
545
|
-
case
|
|
546
|
-
|
|
440
|
+
case 39:
|
|
441
|
+
_context6.next = 44;
|
|
547
442
|
break;
|
|
548
|
-
case
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
reject(
|
|
552
|
-
case
|
|
553
|
-
|
|
443
|
+
case 41:
|
|
444
|
+
_context6.prev = 41;
|
|
445
|
+
_context6.t1 = _context6["catch"](3);
|
|
446
|
+
reject(_context6.t1);
|
|
447
|
+
case 44:
|
|
448
|
+
_context6.next = 47;
|
|
554
449
|
break;
|
|
555
|
-
case
|
|
450
|
+
case 46:
|
|
556
451
|
channel.ack(msg);
|
|
557
|
-
case
|
|
558
|
-
|
|
452
|
+
case 47:
|
|
453
|
+
_context6.next = 50;
|
|
559
454
|
break;
|
|
560
|
-
case
|
|
455
|
+
case 49:
|
|
561
456
|
reject(new Error('msg null'));
|
|
562
|
-
case
|
|
457
|
+
case 50:
|
|
563
458
|
case "end":
|
|
564
|
-
return
|
|
459
|
+
return _context6.stop();
|
|
565
460
|
}
|
|
566
461
|
}
|
|
567
|
-
},
|
|
462
|
+
}, _callee6, null, [[3, 41], [17, 24]]);
|
|
568
463
|
}));
|
|
569
|
-
return function (
|
|
464
|
+
return function (_x5) {
|
|
570
465
|
return _ref.apply(this, arguments);
|
|
571
466
|
};
|
|
572
467
|
}());
|
|
573
468
|
});
|
|
574
469
|
case 14:
|
|
575
|
-
|
|
470
|
+
_context7.next = 28;
|
|
576
471
|
break;
|
|
577
472
|
case 16:
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
473
|
+
_context7.prev = 16;
|
|
474
|
+
_context7.t0 = _context7["catch"](3);
|
|
475
|
+
_context7.prev = 18;
|
|
476
|
+
_context7.next = 21;
|
|
582
477
|
return channel.close();
|
|
583
478
|
case 21:
|
|
584
|
-
|
|
479
|
+
_context7.next = 25;
|
|
585
480
|
break;
|
|
586
481
|
case 23:
|
|
587
|
-
|
|
588
|
-
|
|
482
|
+
_context7.prev = 23;
|
|
483
|
+
_context7.t1 = _context7["catch"](18);
|
|
589
484
|
case 25:
|
|
590
|
-
|
|
485
|
+
_context7.next = 27;
|
|
591
486
|
return (0, _util.timeout)(5000);
|
|
592
487
|
case 27:
|
|
593
|
-
return
|
|
488
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
594
489
|
case 28:
|
|
595
|
-
|
|
490
|
+
_context7.next = 33;
|
|
596
491
|
break;
|
|
597
492
|
case 30:
|
|
598
|
-
|
|
493
|
+
_context7.next = 32;
|
|
599
494
|
return (0, _util.timeout)(5000);
|
|
600
495
|
case 32:
|
|
601
|
-
return
|
|
496
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
602
497
|
case 33:
|
|
603
|
-
return
|
|
498
|
+
return _context7.abrupt("return", true);
|
|
604
499
|
case 34:
|
|
605
500
|
case "end":
|
|
606
|
-
return
|
|
501
|
+
return _context7.stop();
|
|
607
502
|
}
|
|
608
503
|
}
|
|
609
|
-
},
|
|
504
|
+
}, _callee7, this, [[3, 16], [18, 23]]);
|
|
610
505
|
}));
|
|
611
|
-
function consume(
|
|
506
|
+
function consume(_x3, _x4) {
|
|
612
507
|
return _consume.apply(this, arguments);
|
|
613
508
|
}
|
|
614
509
|
return consume;
|
|
@@ -616,20 +511,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
616
511
|
}, {
|
|
617
512
|
key: "selfReceiving",
|
|
618
513
|
value: function () {
|
|
619
|
-
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
620
|
-
return _regeneratorRuntime().wrap(function
|
|
514
|
+
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb, callbackError) {
|
|
515
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
621
516
|
while (1) {
|
|
622
|
-
switch (
|
|
517
|
+
switch (_context8.prev = _context8.next) {
|
|
623
518
|
case 0:
|
|
624
519
|
this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
|
|
625
520
|
case 1:
|
|
626
521
|
case "end":
|
|
627
|
-
return
|
|
522
|
+
return _context8.stop();
|
|
628
523
|
}
|
|
629
524
|
}
|
|
630
|
-
},
|
|
525
|
+
}, _callee8, this);
|
|
631
526
|
}));
|
|
632
|
-
function selfReceiving(
|
|
527
|
+
function selfReceiving(_x6, _x7, _x8) {
|
|
633
528
|
return _selfReceiving.apply(this, arguments);
|
|
634
529
|
}
|
|
635
530
|
return selfReceiving;
|
|
@@ -637,26 +532,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
637
532
|
}, {
|
|
638
533
|
key: "receiving",
|
|
639
534
|
value: function () {
|
|
640
|
-
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
535
|
+
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
|
|
641
536
|
var callbackError,
|
|
642
|
-
|
|
643
|
-
return _regeneratorRuntime().wrap(function
|
|
537
|
+
_args9 = arguments;
|
|
538
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
644
539
|
while (1) {
|
|
645
|
-
switch (
|
|
540
|
+
switch (_context9.prev = _context9.next) {
|
|
646
541
|
case 0:
|
|
647
|
-
callbackError =
|
|
542
|
+
callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
|
|
648
543
|
this.consume(queueName, cb, callbackError);
|
|
649
544
|
if (this.worker) {
|
|
650
545
|
this.selfReceiving(queueName, cb, callbackError);
|
|
651
546
|
}
|
|
652
547
|
case 3:
|
|
653
548
|
case "end":
|
|
654
|
-
return
|
|
549
|
+
return _context9.stop();
|
|
655
550
|
}
|
|
656
551
|
}
|
|
657
|
-
},
|
|
552
|
+
}, _callee9, this);
|
|
658
553
|
}));
|
|
659
|
-
function receiving(
|
|
554
|
+
function receiving(_x9, _x10) {
|
|
660
555
|
return _receiving.apply(this, arguments);
|
|
661
556
|
}
|
|
662
557
|
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,17 +155,9 @@ 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) {
|
|
175
|
-
if (messageQueue.worker && !queueName.startsWith(messageQueue.serverIp)) {
|
|
176
|
-
await messageQueue.send(`${messageQueue.serverIp}_${queueName}`, data);
|
|
177
|
-
} else {
|
|
178
|
-
await messageQueue.send(queueName, data);
|
|
179
|
-
}
|
|
158
|
+
data.retry -= 1;
|
|
159
|
+
if (data.retry > 0) {
|
|
160
|
+
await messageQueue.send(queueName, data);
|
|
180
161
|
} else {
|
|
181
162
|
await messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
182
163
|
queueName,
|
|
@@ -198,7 +179,7 @@ class RabbitMQAsync {
|
|
|
198
179
|
if (callbackError) {
|
|
199
180
|
callbackError(prefixQueueName, err);
|
|
200
181
|
}
|
|
201
|
-
if (data.
|
|
182
|
+
if (data.retry <= 0) {
|
|
202
183
|
await channel.ack(msg);
|
|
203
184
|
} else {
|
|
204
185
|
await channel.nack(msg);
|