@azteam/rabbitmq-async 1.0.212 → 1.0.213
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 +3 -1
- package/lib/RabbitMQAsync.js +4 -2
- package/package.json +1 -1
- package/src/Provider.js +5 -2
- package/src/RabbitMQAsync.js +4 -2
package/lib/Provider.js
CHANGED
|
@@ -19,9 +19,11 @@ 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] : {};
|
|
22
23
|
_classCallCheck(this, Provider);
|
|
23
24
|
this.connections = {};
|
|
24
25
|
this.configs = {};
|
|
26
|
+
this.options = options;
|
|
25
27
|
if (Array.isArray(configs)) {
|
|
26
28
|
configs.map(function (config) {
|
|
27
29
|
_this.configs[config.name] = config;
|
|
@@ -37,7 +39,7 @@ var Provider = /*#__PURE__*/function () {
|
|
|
37
39
|
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'main';
|
|
38
40
|
if (!this.connections[name]) {
|
|
39
41
|
if (this.configs[name]) {
|
|
40
|
-
this.connections[name] = new _RabbitMQAsync["default"](this.configs[name]);
|
|
42
|
+
this.connections[name] = new _RabbitMQAsync["default"](this.configs[name], this.options.retryKey || 'RETRY');
|
|
41
43
|
} else {
|
|
42
44
|
return this.getConnection('main');
|
|
43
45
|
}
|
package/lib/RabbitMQAsync.js
CHANGED
|
@@ -23,6 +23,7 @@ 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';
|
|
26
27
|
_classCallCheck(this, RabbitMQAsync);
|
|
27
28
|
this.connected = false;
|
|
28
29
|
this.username = config.username;
|
|
@@ -31,6 +32,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
31
32
|
this.prefix = config.prefix;
|
|
32
33
|
this.serverIp = config.server_ip;
|
|
33
34
|
this.listConsume = [];
|
|
35
|
+
this.retryKey = retryKey;
|
|
34
36
|
this.client = null;
|
|
35
37
|
this.channel = null;
|
|
36
38
|
setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
@@ -352,7 +354,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
352
354
|
break;
|
|
353
355
|
case 11:
|
|
354
356
|
_context7.next = 13;
|
|
355
|
-
return messageQueue.send(messageQueue.parsePrefix(
|
|
357
|
+
return messageQueue.send(messageQueue.parsePrefix(this.retryKey), {
|
|
356
358
|
queueName: queueName,
|
|
357
359
|
data: data,
|
|
358
360
|
retry_time: new Date(),
|
|
@@ -419,7 +421,7 @@ var RabbitMQAsync = /*#__PURE__*/function () {
|
|
|
419
421
|
case "end":
|
|
420
422
|
return _context7.stop();
|
|
421
423
|
}
|
|
422
|
-
}, _callee7,
|
|
424
|
+
}, _callee7, this, [[3, 41], [17, 24]]);
|
|
423
425
|
}));
|
|
424
426
|
return function (_x5) {
|
|
425
427
|
return _ref2.apply(this, arguments);
|
package/package.json
CHANGED
package/src/Provider.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import RabbitMQAsync from './RabbitMQAsync';
|
|
2
2
|
|
|
3
3
|
class Provider {
|
|
4
|
-
constructor(configs = []) {
|
|
4
|
+
constructor(configs = [], options = {}) {
|
|
5
5
|
this.connections = {};
|
|
6
6
|
this.configs = {};
|
|
7
|
+
|
|
8
|
+
this.options = options;
|
|
9
|
+
|
|
7
10
|
if (Array.isArray(configs)) {
|
|
8
11
|
configs.map((config) => {
|
|
9
12
|
this.configs[config.name] = config;
|
|
@@ -17,7 +20,7 @@ class Provider {
|
|
|
17
20
|
getConnection(name = 'main') {
|
|
18
21
|
if (!this.connections[name]) {
|
|
19
22
|
if (this.configs[name]) {
|
|
20
|
-
this.connections[name] = new RabbitMQAsync(this.configs[name]);
|
|
23
|
+
this.connections[name] = new RabbitMQAsync(this.configs[name], this.options.retryKey || 'RETRY');
|
|
21
24
|
} else {
|
|
22
25
|
return this.getConnection('main');
|
|
23
26
|
}
|
package/src/RabbitMQAsync.js
CHANGED
|
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
|
|
4
4
|
import {timeout} from '@azteam/util';
|
|
5
5
|
|
|
6
6
|
class RabbitMQAsync {
|
|
7
|
-
constructor(config) {
|
|
7
|
+
constructor(config, retryKey = 'RETRY') {
|
|
8
8
|
this.connected = false;
|
|
9
9
|
this.username = config.username;
|
|
10
10
|
this.password = config.password;
|
|
@@ -14,6 +14,8 @@ class RabbitMQAsync {
|
|
|
14
14
|
|
|
15
15
|
this.listConsume = [];
|
|
16
16
|
|
|
17
|
+
this.retryKey = retryKey;
|
|
18
|
+
|
|
17
19
|
this.client = null;
|
|
18
20
|
this.channel = null;
|
|
19
21
|
|
|
@@ -140,7 +142,7 @@ class RabbitMQAsync {
|
|
|
140
142
|
if (data.retry > 0) {
|
|
141
143
|
await messageQueue.send(queueName, data);
|
|
142
144
|
} else {
|
|
143
|
-
await messageQueue.send(messageQueue.parsePrefix(
|
|
145
|
+
await messageQueue.send(messageQueue.parsePrefix(this.retryKey), {
|
|
144
146
|
queueName,
|
|
145
147
|
data,
|
|
146
148
|
retry_time: new Date(),
|