@azteam/rabbitmq-async 1.0.138 → 1.0.139
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 +1 -1
- package/src/RabbitMQAsync.js +35 -30
package/package.json
CHANGED
package/src/RabbitMQAsync.js
CHANGED
|
@@ -136,45 +136,50 @@ class RabbitMQAsync {
|
|
|
136
136
|
|
|
137
137
|
await new Promise((resolve, reject) => {
|
|
138
138
|
channel.consume(prefixQueueName, async function (msg) {
|
|
139
|
-
if (msg
|
|
139
|
+
if (msg) {
|
|
140
140
|
const data = JSON.parse(msg.content.toString());
|
|
141
|
-
try {
|
|
142
|
-
if (msg.fields.redelivered) {
|
|
143
|
-
if (!data.retry) {
|
|
144
|
-
data.retry = 0;
|
|
145
|
-
}
|
|
146
|
-
data.retry += 1;
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
data,
|
|
154
|
-
retry_time: new Date(),
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
await channel.ack(msg);
|
|
158
|
-
} else {
|
|
159
|
-
try {
|
|
160
|
-
await cb(data);
|
|
161
|
-
await channel.ack(msg);
|
|
162
|
-
} catch (err) {
|
|
163
|
-
if (callbackError) {
|
|
164
|
-
callbackError(prefixQueueName, err);
|
|
142
|
+
if (data) {
|
|
143
|
+
try {
|
|
144
|
+
if (msg.fields.redelivered) {
|
|
145
|
+
if (!data.retry) {
|
|
146
|
+
data.retry = 0;
|
|
165
147
|
}
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
data.retry += 1;
|
|
149
|
+
|
|
150
|
+
if (data.retry < 5) {
|
|
151
|
+
await messageQueue.send(queueName, data);
|
|
168
152
|
} else {
|
|
169
|
-
await
|
|
153
|
+
await messageQueue.send(messageQueue.parsePrefix('RETRY'), {
|
|
154
|
+
queueName,
|
|
155
|
+
data,
|
|
156
|
+
retry_time: new Date(),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
await channel.ack(msg);
|
|
160
|
+
} else {
|
|
161
|
+
try {
|
|
162
|
+
await cb(data);
|
|
163
|
+
await channel.ack(msg);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (callbackError) {
|
|
166
|
+
callbackError(prefixQueueName, err);
|
|
167
|
+
}
|
|
168
|
+
if (data.noRetry) {
|
|
169
|
+
await channel.ack(msg);
|
|
170
|
+
} else {
|
|
171
|
+
await channel.nack(msg);
|
|
172
|
+
}
|
|
170
173
|
}
|
|
171
174
|
}
|
|
175
|
+
} catch (err) {
|
|
176
|
+
reject(err);
|
|
172
177
|
}
|
|
173
|
-
}
|
|
174
|
-
|
|
178
|
+
} else {
|
|
179
|
+
channel.ack(msg);
|
|
175
180
|
}
|
|
176
181
|
} else {
|
|
177
|
-
|
|
182
|
+
reject(new Error('msg null'));
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
185
|
});
|