@autofleet/rabbit 2.0.4-beta → 2.0.4-beta1
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/index.ts +14 -12
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -37,16 +37,14 @@ const defaultOptions = {
|
|
|
37
37
|
|
|
38
38
|
const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
|
|
39
39
|
|
|
40
|
-
const callbackWithTimeout = async (callback: any, args: any[], timeout: number, timeoutMessage = 'Timeout while ack message') =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}).timeout(timeout, timeoutMessage);
|
|
49
|
-
};
|
|
40
|
+
const callbackWithTimeout = async (callback: any, args: any[], timeout: number, timeoutMessage = 'Timeout while ack message') => Promise.race([
|
|
41
|
+
new Promise(callback(...args)),
|
|
42
|
+
new Promise((resolve, reject) => {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
reject(timeoutMessage);
|
|
45
|
+
}, timeout);
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
50
48
|
|
|
51
49
|
const connectionCreatedConst = 'connectionCreated';
|
|
52
50
|
class RabbitMq implements IAfRabbitMq {
|
|
@@ -226,7 +224,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
226
224
|
return Promise.all([
|
|
227
225
|
c.consume(
|
|
228
226
|
queue,
|
|
229
|
-
(msg: any) => {
|
|
227
|
+
async (msg: any) => {
|
|
230
228
|
newTrace(traceTypes.RABBIT);
|
|
231
229
|
if (optionsWithDefaults.timeout) {
|
|
232
230
|
const args = [
|
|
@@ -234,7 +232,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
234
232
|
this.ack(channel),
|
|
235
233
|
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
236
234
|
];
|
|
237
|
-
|
|
235
|
+
try {
|
|
236
|
+
await callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
|
|
239
|
+
}
|
|
238
240
|
} else {
|
|
239
241
|
callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
240
242
|
}
|