@azteam/rabbitmq-async 1.0.118 → 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 +1 -1
- package/src/RabbitMQAsync.js +22 -10
package/package.json
CHANGED
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;
|
|
@@ -134,23 +136,33 @@ class RabbitMQAsync {
|
|
|
134
136
|
}
|
|
135
137
|
await channel.ack(msg);
|
|
136
138
|
} catch (err) {
|
|
137
|
-
|
|
138
|
-
|
|
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
|
+
}
|
|
139
147
|
}
|
|
140
148
|
});
|
|
141
149
|
} catch (err) {
|
|
142
150
|
try {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
if (channel) {
|
|
152
|
+
channel.close();
|
|
153
|
+
}
|
|
154
|
+
} catch (err2) {}
|
|
146
155
|
await timeout(5000);
|
|
147
|
-
|
|
156
|
+
if (callbackError) {
|
|
157
|
+
callbackError(prefixQueueName, err);
|
|
158
|
+
}
|
|
148
159
|
return this.receiving(queueName, cb, callbackError);
|
|
149
160
|
}
|
|
150
161
|
} else {
|
|
151
162
|
await timeout(5000);
|
|
152
163
|
return this.receiving(queueName, cb, callbackError);
|
|
153
164
|
}
|
|
165
|
+
return false;
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
setAlertCallback(callback) {
|
|
@@ -161,7 +173,7 @@ class RabbitMQAsync {
|
|
|
161
173
|
if (typeof this.alertCallback === 'function') {
|
|
162
174
|
this.alertCallback(status, msg);
|
|
163
175
|
} else {
|
|
164
|
-
console.
|
|
176
|
+
console.info(status, msg);
|
|
165
177
|
}
|
|
166
178
|
}
|
|
167
179
|
}
|