@azteam/rabbitmq-async 1.0.166 → 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 -224
- package/package.json +1 -1
- package/src/RabbitMQAsync.js +13 -24
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,142 +257,64 @@ 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;
|
|
@@ -393,201 +322,198 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
393
322
|
}, {
|
|
394
323
|
key: "consume",
|
|
395
324
|
value: function () {
|
|
396
|
-
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
325
|
+
var _consume = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(queueName, cb) {
|
|
397
326
|
var callbackError,
|
|
398
327
|
prefixQueueName,
|
|
399
328
|
channel,
|
|
400
329
|
messageQueue,
|
|
401
|
-
|
|
402
|
-
return _regeneratorRuntime().wrap(function
|
|
330
|
+
_args7 = arguments;
|
|
331
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
403
332
|
while (1) {
|
|
404
|
-
switch (
|
|
333
|
+
switch (_context7.prev = _context7.next) {
|
|
405
334
|
case 0:
|
|
406
|
-
callbackError =
|
|
335
|
+
callbackError = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
|
|
407
336
|
prefixQueueName = this.parsePrefix(queueName);
|
|
408
337
|
if (!this.connected) {
|
|
409
|
-
|
|
338
|
+
_context7.next = 30;
|
|
410
339
|
break;
|
|
411
340
|
}
|
|
412
|
-
|
|
413
|
-
|
|
341
|
+
_context7.prev = 3;
|
|
342
|
+
_context7.next = 6;
|
|
414
343
|
return this.client.createChannel();
|
|
415
344
|
case 6:
|
|
416
|
-
channel =
|
|
417
|
-
|
|
345
|
+
channel = _context7.sent;
|
|
346
|
+
_context7.next = 9;
|
|
418
347
|
return channel.assertQueue(prefixQueueName, {
|
|
419
348
|
durable: true
|
|
420
349
|
});
|
|
421
350
|
case 9:
|
|
422
|
-
|
|
351
|
+
_context7.next = 11;
|
|
423
352
|
return channel.prefetch(1);
|
|
424
353
|
case 11:
|
|
425
354
|
messageQueue = this;
|
|
426
|
-
|
|
355
|
+
_context7.next = 14;
|
|
427
356
|
return new Promise(function (resolve, reject) {
|
|
428
357
|
channel.consume(prefixQueueName, /*#__PURE__*/function () {
|
|
429
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
358
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(msg) {
|
|
430
359
|
var data, errString;
|
|
431
|
-
return _regeneratorRuntime().wrap(function
|
|
360
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
432
361
|
while (1) {
|
|
433
|
-
switch (
|
|
362
|
+
switch (_context6.prev = _context6.next) {
|
|
434
363
|
case 0:
|
|
435
364
|
if (!msg) {
|
|
436
|
-
|
|
365
|
+
_context6.next = 54;
|
|
437
366
|
break;
|
|
438
367
|
}
|
|
439
368
|
data = JSON.parse(msg.content.toString());
|
|
440
369
|
if (!data) {
|
|
441
|
-
|
|
370
|
+
_context6.next = 51;
|
|
442
371
|
break;
|
|
443
372
|
}
|
|
444
|
-
|
|
373
|
+
_context6.prev = 3;
|
|
445
374
|
if (!msg.fields.redelivered) {
|
|
446
|
-
|
|
375
|
+
_context6.next = 22;
|
|
447
376
|
break;
|
|
448
377
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
data.retry += 1;
|
|
453
|
-
if (!(data.retry < 5)) {
|
|
454
|
-
_context9.next = 17;
|
|
378
|
+
data.retry -= 1;
|
|
379
|
+
if (!(data.retry > 0)) {
|
|
380
|
+
_context6.next = 16;
|
|
455
381
|
break;
|
|
456
382
|
}
|
|
457
383
|
if (!(messageQueue.worker && !queueName.startsWith(messageQueue.serverIp))) {
|
|
458
|
-
|
|
384
|
+
_context6.next = 12;
|
|
459
385
|
break;
|
|
460
386
|
}
|
|
461
|
-
|
|
387
|
+
_context6.next = 10;
|
|
462
388
|
return messageQueue.send("".concat(messageQueue.serverIp, "_").concat(queueName), data);
|
|
463
|
-
case
|
|
464
|
-
|
|
389
|
+
case 10:
|
|
390
|
+
_context6.next = 14;
|
|
465
391
|
break;
|
|
466
|
-
case
|
|
467
|
-
|
|
392
|
+
case 12:
|
|
393
|
+
_context6.next = 14;
|
|
468
394
|
return messageQueue.send(queueName, data);
|
|
469
|
-
case
|
|
470
|
-
|
|
395
|
+
case 14:
|
|
396
|
+
_context6.next = 18;
|
|
471
397
|
break;
|
|
472
|
-
case
|
|
473
|
-
|
|
398
|
+
case 16:
|
|
399
|
+
_context6.next = 18;
|
|
474
400
|
return messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
475
401
|
queueName: queueName,
|
|
476
402
|
data: data,
|
|
477
403
|
retry_time: new Date()
|
|
478
404
|
});
|
|
479
|
-
case
|
|
480
|
-
|
|
405
|
+
case 18:
|
|
406
|
+
_context6.next = 20;
|
|
481
407
|
return channel.ack(msg);
|
|
482
|
-
case
|
|
483
|
-
|
|
408
|
+
case 20:
|
|
409
|
+
_context6.next = 44;
|
|
484
410
|
break;
|
|
485
|
-
case
|
|
486
|
-
|
|
487
|
-
|
|
411
|
+
case 22:
|
|
412
|
+
_context6.prev = 22;
|
|
413
|
+
_context6.next = 25;
|
|
488
414
|
return cb(data);
|
|
489
|
-
case
|
|
490
|
-
|
|
415
|
+
case 25:
|
|
416
|
+
_context6.next = 27;
|
|
491
417
|
return channel.ack(msg);
|
|
492
|
-
case
|
|
493
|
-
|
|
418
|
+
case 27:
|
|
419
|
+
_context6.next = 44;
|
|
494
420
|
break;
|
|
495
|
-
case
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
errString =
|
|
421
|
+
case 29:
|
|
422
|
+
_context6.prev = 29;
|
|
423
|
+
_context6.t0 = _context6["catch"](22);
|
|
424
|
+
errString = _context6.t0.toString();
|
|
499
425
|
if (!_lodash["default"].some(['IllegalOperationError: Channel closed'], function (el) {
|
|
500
426
|
return _lodash["default"].includes(errString, el);
|
|
501
427
|
})) {
|
|
502
|
-
|
|
428
|
+
_context6.next = 36;
|
|
503
429
|
break;
|
|
504
430
|
}
|
|
505
431
|
reject(new Error(errString));
|
|
506
|
-
|
|
432
|
+
_context6.next = 44;
|
|
507
433
|
break;
|
|
508
|
-
case
|
|
434
|
+
case 36:
|
|
509
435
|
if (callbackError) {
|
|
510
|
-
callbackError(prefixQueueName,
|
|
436
|
+
callbackError(prefixQueueName, _context6.t0);
|
|
511
437
|
}
|
|
512
|
-
if (!data.
|
|
513
|
-
|
|
438
|
+
if (!(data.retry <= 0)) {
|
|
439
|
+
_context6.next = 42;
|
|
514
440
|
break;
|
|
515
441
|
}
|
|
516
|
-
|
|
442
|
+
_context6.next = 40;
|
|
517
443
|
return channel.ack(msg);
|
|
518
|
-
case
|
|
519
|
-
|
|
444
|
+
case 40:
|
|
445
|
+
_context6.next = 44;
|
|
520
446
|
break;
|
|
521
|
-
case
|
|
522
|
-
|
|
447
|
+
case 42:
|
|
448
|
+
_context6.next = 44;
|
|
523
449
|
return channel.nack(msg);
|
|
524
|
-
case
|
|
525
|
-
|
|
450
|
+
case 44:
|
|
451
|
+
_context6.next = 49;
|
|
526
452
|
break;
|
|
527
|
-
case
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
reject(
|
|
531
|
-
case
|
|
532
|
-
|
|
453
|
+
case 46:
|
|
454
|
+
_context6.prev = 46;
|
|
455
|
+
_context6.t1 = _context6["catch"](3);
|
|
456
|
+
reject(_context6.t1);
|
|
457
|
+
case 49:
|
|
458
|
+
_context6.next = 52;
|
|
533
459
|
break;
|
|
534
|
-
case
|
|
460
|
+
case 51:
|
|
535
461
|
channel.ack(msg);
|
|
536
|
-
case
|
|
537
|
-
|
|
462
|
+
case 52:
|
|
463
|
+
_context6.next = 55;
|
|
538
464
|
break;
|
|
539
|
-
case
|
|
465
|
+
case 54:
|
|
540
466
|
reject(new Error('msg null'));
|
|
541
|
-
case
|
|
467
|
+
case 55:
|
|
542
468
|
case "end":
|
|
543
|
-
return
|
|
469
|
+
return _context6.stop();
|
|
544
470
|
}
|
|
545
471
|
}
|
|
546
|
-
},
|
|
472
|
+
}, _callee6, null, [[3, 46], [22, 29]]);
|
|
547
473
|
}));
|
|
548
|
-
return function (
|
|
474
|
+
return function (_x5) {
|
|
549
475
|
return _ref.apply(this, arguments);
|
|
550
476
|
};
|
|
551
477
|
}());
|
|
552
478
|
});
|
|
553
479
|
case 14:
|
|
554
|
-
|
|
480
|
+
_context7.next = 28;
|
|
555
481
|
break;
|
|
556
482
|
case 16:
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
483
|
+
_context7.prev = 16;
|
|
484
|
+
_context7.t0 = _context7["catch"](3);
|
|
485
|
+
_context7.prev = 18;
|
|
486
|
+
_context7.next = 21;
|
|
561
487
|
return channel.close();
|
|
562
488
|
case 21:
|
|
563
|
-
|
|
489
|
+
_context7.next = 25;
|
|
564
490
|
break;
|
|
565
491
|
case 23:
|
|
566
|
-
|
|
567
|
-
|
|
492
|
+
_context7.prev = 23;
|
|
493
|
+
_context7.t1 = _context7["catch"](18);
|
|
568
494
|
case 25:
|
|
569
|
-
|
|
495
|
+
_context7.next = 27;
|
|
570
496
|
return (0, _util.timeout)(5000);
|
|
571
497
|
case 27:
|
|
572
|
-
return
|
|
498
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
573
499
|
case 28:
|
|
574
|
-
|
|
500
|
+
_context7.next = 33;
|
|
575
501
|
break;
|
|
576
502
|
case 30:
|
|
577
|
-
|
|
503
|
+
_context7.next = 32;
|
|
578
504
|
return (0, _util.timeout)(5000);
|
|
579
505
|
case 32:
|
|
580
|
-
return
|
|
506
|
+
return _context7.abrupt("return", this.consume(queueName, cb, callbackError));
|
|
581
507
|
case 33:
|
|
582
|
-
return
|
|
508
|
+
return _context7.abrupt("return", true);
|
|
583
509
|
case 34:
|
|
584
510
|
case "end":
|
|
585
|
-
return
|
|
511
|
+
return _context7.stop();
|
|
586
512
|
}
|
|
587
513
|
}
|
|
588
|
-
},
|
|
514
|
+
}, _callee7, this, [[3, 16], [18, 23]]);
|
|
589
515
|
}));
|
|
590
|
-
function consume(
|
|
516
|
+
function consume(_x3, _x4) {
|
|
591
517
|
return _consume.apply(this, arguments);
|
|
592
518
|
}
|
|
593
519
|
return consume;
|
|
@@ -595,20 +521,20 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
595
521
|
}, {
|
|
596
522
|
key: "selfReceiving",
|
|
597
523
|
value: function () {
|
|
598
|
-
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
599
|
-
return _regeneratorRuntime().wrap(function
|
|
524
|
+
var _selfReceiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(queueName, cb, callbackError) {
|
|
525
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
600
526
|
while (1) {
|
|
601
|
-
switch (
|
|
527
|
+
switch (_context8.prev = _context8.next) {
|
|
602
528
|
case 0:
|
|
603
529
|
this.consume("".concat(this.serverIp, "_").concat(queueName), cb, callbackError);
|
|
604
530
|
case 1:
|
|
605
531
|
case "end":
|
|
606
|
-
return
|
|
532
|
+
return _context8.stop();
|
|
607
533
|
}
|
|
608
534
|
}
|
|
609
|
-
},
|
|
535
|
+
}, _callee8, this);
|
|
610
536
|
}));
|
|
611
|
-
function selfReceiving(
|
|
537
|
+
function selfReceiving(_x6, _x7, _x8) {
|
|
612
538
|
return _selfReceiving.apply(this, arguments);
|
|
613
539
|
}
|
|
614
540
|
return selfReceiving;
|
|
@@ -616,26 +542,26 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
616
542
|
}, {
|
|
617
543
|
key: "receiving",
|
|
618
544
|
value: function () {
|
|
619
|
-
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
545
|
+
var _receiving = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(queueName, cb) {
|
|
620
546
|
var callbackError,
|
|
621
|
-
|
|
622
|
-
return _regeneratorRuntime().wrap(function
|
|
547
|
+
_args9 = arguments;
|
|
548
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
623
549
|
while (1) {
|
|
624
|
-
switch (
|
|
550
|
+
switch (_context9.prev = _context9.next) {
|
|
625
551
|
case 0:
|
|
626
|
-
callbackError =
|
|
552
|
+
callbackError = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
|
|
627
553
|
this.consume(queueName, cb, callbackError);
|
|
628
554
|
if (this.worker) {
|
|
629
555
|
this.selfReceiving(queueName, cb, callbackError);
|
|
630
556
|
}
|
|
631
557
|
case 3:
|
|
632
558
|
case "end":
|
|
633
|
-
return
|
|
559
|
+
return _context9.stop();
|
|
634
560
|
}
|
|
635
561
|
}
|
|
636
|
-
},
|
|
562
|
+
}, _callee9, this);
|
|
637
563
|
}));
|
|
638
|
-
function receiving(
|
|
564
|
+
function receiving(_x9, _x10) {
|
|
639
565
|
return _receiving.apply(this, arguments);
|
|
640
566
|
}
|
|
641
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;
|
|
@@ -162,12 +155,8 @@ class RabbitMQAsync {
|
|
|
162
155
|
if (data) {
|
|
163
156
|
try {
|
|
164
157
|
if (msg.fields.redelivered) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
data.retry += 1;
|
|
169
|
-
|
|
170
|
-
if (data.retry < 5) {
|
|
158
|
+
data.retry -= 1;
|
|
159
|
+
if (data.retry > 0) {
|
|
171
160
|
if (messageQueue.worker && !queueName.startsWith(messageQueue.serverIp)) {
|
|
172
161
|
await messageQueue.send(`${messageQueue.serverIp}_${queueName}`, data);
|
|
173
162
|
} else {
|
|
@@ -194,7 +183,7 @@ class RabbitMQAsync {
|
|
|
194
183
|
if (callbackError) {
|
|
195
184
|
callbackError(prefixQueueName, err);
|
|
196
185
|
}
|
|
197
|
-
if (data.
|
|
186
|
+
if (data.retry <= 0) {
|
|
198
187
|
await channel.ack(msg);
|
|
199
188
|
} else {
|
|
200
189
|
await channel.nack(msg);
|