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