@azteam/rabbitmq-async 1.0.116 → 1.0.119
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/package.json +2 -2
- package/src/RabbitMQAsync.js +23 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azteam/rabbitmq-async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.119",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "toda <sp.azsolution.net@gmail.com>",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@azteam/util": "1.0.
|
|
19
|
+
"@azteam/util": "1.0.11",
|
|
20
20
|
"amqplib": "0.8.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/RabbitMQAsync.js
CHANGED
|
@@ -87,14 +87,15 @@ class RabbitMQAsync {
|
|
|
87
87
|
return this.send(queueName, msg);
|
|
88
88
|
} finally {
|
|
89
89
|
try {
|
|
90
|
-
|
|
90
|
+
if (channel) {
|
|
91
|
+
channel.close();
|
|
92
|
+
}
|
|
91
93
|
} catch (err) {}
|
|
92
94
|
}
|
|
93
95
|
} else {
|
|
94
96
|
await timeout(5000);
|
|
95
97
|
return this.send(queueName, msg);
|
|
96
98
|
}
|
|
97
|
-
return false;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
async receiving(queueName, cb, callbackError = null) {
|
|
@@ -112,8 +113,9 @@ class RabbitMQAsync {
|
|
|
112
113
|
|
|
113
114
|
const messageQueue = this;
|
|
114
115
|
channel.consume(prefixQueueName, async function (msg) {
|
|
116
|
+
const data = JSON.parse(msg.content.toString());
|
|
117
|
+
|
|
115
118
|
try {
|
|
116
|
-
const data = JSON.parse(msg.content.toString());
|
|
117
119
|
if (msg.fields.redelivered) {
|
|
118
120
|
if (!data.retry) {
|
|
119
121
|
data.retry = 0;
|
|
@@ -126,6 +128,7 @@ class RabbitMQAsync {
|
|
|
126
128
|
await messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
127
129
|
queueName,
|
|
128
130
|
data,
|
|
131
|
+
retry_time: new Date(),
|
|
129
132
|
});
|
|
130
133
|
}
|
|
131
134
|
} else {
|
|
@@ -133,22 +136,33 @@ class RabbitMQAsync {
|
|
|
133
136
|
}
|
|
134
137
|
await channel.ack(msg);
|
|
135
138
|
} catch (err) {
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
if (data.noRetry) {
|
|
140
|
+
await channel.ack(msg);
|
|
141
|
+
} else {
|
|
142
|
+
await channel.nack(msg);
|
|
143
|
+
}
|
|
144
|
+
if (callbackError) {
|
|
145
|
+
callbackError(prefixQueueName, err);
|
|
146
|
+
}
|
|
138
147
|
}
|
|
139
148
|
});
|
|
140
149
|
} catch (err) {
|
|
141
150
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
if (channel) {
|
|
152
|
+
channel.close();
|
|
153
|
+
}
|
|
154
|
+
} catch (err2) {}
|
|
144
155
|
await timeout(5000);
|
|
145
|
-
|
|
156
|
+
if (callbackError) {
|
|
157
|
+
callbackError(prefixQueueName, err);
|
|
158
|
+
}
|
|
146
159
|
return this.receiving(queueName, cb, callbackError);
|
|
147
160
|
}
|
|
148
161
|
} else {
|
|
149
162
|
await timeout(5000);
|
|
150
163
|
return this.receiving(queueName, cb, callbackError);
|
|
151
164
|
}
|
|
165
|
+
return false;
|
|
152
166
|
}
|
|
153
167
|
|
|
154
168
|
setAlertCallback(callback) {
|
|
@@ -159,7 +173,7 @@ class RabbitMQAsync {
|
|
|
159
173
|
if (typeof this.alertCallback === 'function') {
|
|
160
174
|
this.alertCallback(status, msg);
|
|
161
175
|
} else {
|
|
162
|
-
console.
|
|
176
|
+
console.info(status, msg);
|
|
163
177
|
}
|
|
164
178
|
}
|
|
165
179
|
}
|