@azteam/rabbitmq-async 1.0.213 → 1.0.215
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/Provider.js +1 -3
- package/lib/RabbitMQAsync.js +6 -6
- package/package.json +1 -1
- package/src/Provider.js +2 -4
- package/src/RabbitMQAsync.js +4 -5
package/lib/Provider.js
CHANGED
|
@@ -19,11 +19,9 @@ var Provider = /*#__PURE__*/function () {
|
|
|
19
19
|
function Provider() {
|
|
20
20
|
var _this = this;
|
|
21
21
|
var configs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
22
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
22
|
_classCallCheck(this, Provider);
|
|
24
23
|
this.connections = {};
|
|
25
24
|
this.configs = {};
|
|
26
|
-
this.options = options;
|
|
27
25
|
if (Array.isArray(configs)) {
|
|
28
26
|
configs.map(function (config) {
|
|
29
27
|
_this.configs[config.name] = config;
|
|
@@ -39,7 +37,7 @@ var Provider = /*#__PURE__*/function () {
|
|
|
39
37
|
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'main';
|
|
40
38
|
if (!this.connections[name]) {
|
|
41
39
|
if (this.configs[name]) {
|
|
42
|
-
this.connections[name] = new _RabbitMQAsync["default"](this.configs[name]
|
|
40
|
+
this.connections[name] = new _RabbitMQAsync["default"](this.configs[name]);
|
|
43
41
|
} else {
|
|
44
42
|
return this.getConnection('main');
|
|
45
43
|
}
|
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -23,7 +23,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
23
23
|
var RabbitMQAsync = /*#__PURE__*/function () {
|
|
24
24
|
function RabbitMQAsync(config) {
|
|
25
25
|
var _this = this;
|
|
26
|
-
var retryKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'RETRY';
|
|
27
26
|
_classCallCheck(this, RabbitMQAsync);
|
|
28
27
|
this.connected = false;
|
|
29
28
|
this.username = config.username;
|
|
@@ -31,8 +30,8 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
31
30
|
this.host = config.host;
|
|
32
31
|
this.prefix = config.prefix;
|
|
33
32
|
this.serverIp = config.server_ip;
|
|
33
|
+
this.retryKey = config.retry_key;
|
|
34
34
|
this.listConsume = [];
|
|
35
|
-
this.retryKey = retryKey;
|
|
36
35
|
this.client = null;
|
|
37
36
|
this.channel = null;
|
|
38
37
|
setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
@@ -354,7 +353,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
354
353
|
break;
|
|
355
354
|
case 11:
|
|
356
355
|
_context7.next = 13;
|
|
357
|
-
return messageQueue.send(messageQueue.parsePrefix(
|
|
356
|
+
return messageQueue.send(messageQueue.parsePrefix(messageQueue.retryKey), {
|
|
358
357
|
queueName: queueName,
|
|
359
358
|
data: data,
|
|
360
359
|
retry_time: new Date(),
|
|
@@ -421,7 +420,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
421
420
|
case "end":
|
|
422
421
|
return _context7.stop();
|
|
423
422
|
}
|
|
424
|
-
}, _callee7,
|
|
423
|
+
}, _callee7, null, [[3, 41], [17, 24]]);
|
|
425
424
|
}));
|
|
426
425
|
return function (_x5) {
|
|
427
426
|
return _ref2.apply(this, arguments);
|
|
@@ -429,7 +428,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
429
428
|
}());
|
|
430
429
|
});
|
|
431
430
|
case 10:
|
|
432
|
-
_context8.next =
|
|
431
|
+
_context8.next = 18;
|
|
433
432
|
break;
|
|
434
433
|
case 12:
|
|
435
434
|
_context8.prev = 12;
|
|
@@ -437,8 +436,9 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
437
436
|
_context8.next = 16;
|
|
438
437
|
return (0, _util.timeout)(5000);
|
|
439
438
|
case 16:
|
|
439
|
+
this._alert('error', _context8.t0);
|
|
440
440
|
return _context8.abrupt("return", this.consume(queueName, asyncFunction, callbackError));
|
|
441
|
-
case
|
|
441
|
+
case 18:
|
|
442
442
|
case "end":
|
|
443
443
|
return _context8.stop();
|
|
444
444
|
}
|
package/package.json
CHANGED
package/src/Provider.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import RabbitMQAsync from './RabbitMQAsync';
|
|
2
2
|
|
|
3
3
|
class Provider {
|
|
4
|
-
constructor(configs = []
|
|
4
|
+
constructor(configs = []) {
|
|
5
5
|
this.connections = {};
|
|
6
6
|
this.configs = {};
|
|
7
7
|
|
|
8
|
-
this.options = options;
|
|
9
|
-
|
|
10
8
|
if (Array.isArray(configs)) {
|
|
11
9
|
configs.map((config) => {
|
|
12
10
|
this.configs[config.name] = config;
|
|
@@ -20,7 +18,7 @@ class Provider {
|
|
|
20
18
|
getConnection(name = 'main') {
|
|
21
19
|
if (!this.connections[name]) {
|
|
22
20
|
if (this.configs[name]) {
|
|
23
|
-
this.connections[name] = new RabbitMQAsync(this.configs[name]
|
|
21
|
+
this.connections[name] = new RabbitMQAsync(this.configs[name]);
|
|
24
22
|
} else {
|
|
25
23
|
return this.getConnection('main');
|
|
26
24
|
}
|
package/src/RabbitMQAsync.js
CHANGED
|
@@ -4,18 +4,17 @@ import _ from 'lodash';
|
|
|
4
4
|
import {timeout} from '@azteam/util';
|
|
5
5
|
|
|
6
6
|
class RabbitMQAsync {
|
|
7
|
-
constructor(config
|
|
7
|
+
constructor(config) {
|
|
8
8
|
this.connected = false;
|
|
9
9
|
this.username = config.username;
|
|
10
10
|
this.password = config.password;
|
|
11
11
|
this.host = config.host;
|
|
12
12
|
this.prefix = config.prefix;
|
|
13
13
|
this.serverIp = config.server_ip;
|
|
14
|
+
this.retryKey = config.retry_key;
|
|
14
15
|
|
|
15
16
|
this.listConsume = [];
|
|
16
17
|
|
|
17
|
-
this.retryKey = retryKey;
|
|
18
|
-
|
|
19
18
|
this.client = null;
|
|
20
19
|
this.channel = null;
|
|
21
20
|
|
|
@@ -134,7 +133,6 @@ class RabbitMQAsync {
|
|
|
134
133
|
channel.consume(prefixQueueName, async function (msg) {
|
|
135
134
|
if (msg) {
|
|
136
135
|
const data = JSON.parse(msg.content.toString());
|
|
137
|
-
|
|
138
136
|
if (data) {
|
|
139
137
|
try {
|
|
140
138
|
if (msg.fields.redelivered) {
|
|
@@ -142,7 +140,7 @@ class RabbitMQAsync {
|
|
|
142
140
|
if (data.retry > 0) {
|
|
143
141
|
await messageQueue.send(queueName, data);
|
|
144
142
|
} else {
|
|
145
|
-
await messageQueue.send(messageQueue.parsePrefix(
|
|
143
|
+
await messageQueue.send(messageQueue.parsePrefix(messageQueue.retryKey), {
|
|
146
144
|
queueName,
|
|
147
145
|
data,
|
|
148
146
|
retry_time: new Date(),
|
|
@@ -183,6 +181,7 @@ class RabbitMQAsync {
|
|
|
183
181
|
}
|
|
184
182
|
} catch (err3) {
|
|
185
183
|
await timeout(5000);
|
|
184
|
+
this._alert('error', err3);
|
|
186
185
|
return this.consume(queueName, asyncFunction, callbackError);
|
|
187
186
|
}
|
|
188
187
|
}
|