@autofleet/rabbit 2.0.4-beta → 2.0.4-beta2
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/dist/index.js +18 -12
- package/package.json +1 -1
- package/src/index.ts +16 -10
package/dist/index.js
CHANGED
|
@@ -46,15 +46,16 @@ const defaultOptions = {
|
|
|
46
46
|
};
|
|
47
47
|
const assertExchangeFanout = (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
|
|
48
48
|
const callbackWithTimeout = (callback, args, timeout, timeoutMessage = 'Timeout while ack message') => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const callbackPromise = new bluebird.Promise(callback(...args));
|
|
50
|
+
Promise.race([
|
|
51
|
+
callbackPromise,
|
|
52
|
+
new Promise((resolve, reject) => {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
callbackPromise.cancel();
|
|
55
|
+
reject(timeoutMessage);
|
|
56
|
+
}, timeout);
|
|
57
|
+
}),
|
|
58
|
+
]);
|
|
58
59
|
});
|
|
59
60
|
const connectionCreatedConst = 'connectionCreated';
|
|
60
61
|
class RabbitMq {
|
|
@@ -204,7 +205,7 @@ class RabbitMq {
|
|
|
204
205
|
yield c.assertQueue(queue);
|
|
205
206
|
yield c.prefetch(limit, true);
|
|
206
207
|
return Promise.all([
|
|
207
|
-
c.consume(queue, (msg) => {
|
|
208
|
+
c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
208
209
|
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
209
210
|
if (optionsWithDefaults.timeout) {
|
|
210
211
|
const args = [
|
|
@@ -212,12 +213,17 @@ class RabbitMq {
|
|
|
212
213
|
this.ack(channel),
|
|
213
214
|
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
214
215
|
];
|
|
215
|
-
|
|
216
|
+
try {
|
|
217
|
+
yield callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
|
|
221
|
+
}
|
|
216
222
|
}
|
|
217
223
|
else {
|
|
218
224
|
callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
219
225
|
}
|
|
220
|
-
}),
|
|
226
|
+
})),
|
|
221
227
|
]);
|
|
222
228
|
}));
|
|
223
229
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,14 +38,16 @@ const defaultOptions = {
|
|
|
38
38
|
const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
|
|
39
39
|
|
|
40
40
|
const callbackWithTimeout = async (callback: any, args: any[], timeout: number, timeoutMessage = 'Timeout while ack message') => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
const callbackPromise = new bluebird.Promise(callback(...args));
|
|
42
|
+
Promise.race([
|
|
43
|
+
callbackPromise,
|
|
44
|
+
new Promise((resolve, reject) => {
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
callbackPromise.cancel();
|
|
47
|
+
reject(timeoutMessage);
|
|
48
|
+
}, timeout);
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
const connectionCreatedConst = 'connectionCreated';
|
|
@@ -226,7 +228,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
226
228
|
return Promise.all([
|
|
227
229
|
c.consume(
|
|
228
230
|
queue,
|
|
229
|
-
(msg: any) => {
|
|
231
|
+
async (msg: any) => {
|
|
230
232
|
newTrace(traceTypes.RABBIT);
|
|
231
233
|
if (optionsWithDefaults.timeout) {
|
|
232
234
|
const args = [
|
|
@@ -234,7 +236,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
234
236
|
this.ack(channel),
|
|
235
237
|
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
236
238
|
];
|
|
237
|
-
|
|
239
|
+
try {
|
|
240
|
+
await callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
|
|
243
|
+
}
|
|
238
244
|
} else {
|
|
239
245
|
callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
240
246
|
}
|