@autofleet/rabbit 2.0.3 → 2.0.4-alpha
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 +19 -0
- package/package.json +1 -1
- package/src/index.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -45,6 +45,17 @@ const defaultOptions = {
|
|
|
45
45
|
deadMessageTtl: DEFAULT_DEAD_TTL_TWO_DAYS,
|
|
46
46
|
};
|
|
47
47
|
const assertExchangeFanout = (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
|
|
48
|
+
const callbackWithTimeout = (callback, args, timeout, timeoutMessage = 'Timeout while ack message') => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
yield new bluebird.Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
yield callback(...args);
|
|
52
|
+
return resolve();
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return reject(e);
|
|
56
|
+
}
|
|
57
|
+
})).timeout(timeout, timeoutMessage);
|
|
58
|
+
});
|
|
48
59
|
const connectionCreatedConst = 'connectionCreated';
|
|
49
60
|
class RabbitMq {
|
|
50
61
|
constructor(options) {
|
|
@@ -194,6 +205,14 @@ class RabbitMq {
|
|
|
194
205
|
return Promise.all([
|
|
195
206
|
c.consume(queue, (msg) => {
|
|
196
207
|
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
208
|
+
if (optionsWithDefaults.timeout) {
|
|
209
|
+
const args = [
|
|
210
|
+
RabbitMq.parseMsg(msg),
|
|
211
|
+
this.ack(channel),
|
|
212
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
213
|
+
];
|
|
214
|
+
callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
|
|
215
|
+
}
|
|
197
216
|
callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
198
217
|
}),
|
|
199
218
|
]);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -37,6 +37,17 @@ 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
|
+
await new bluebird.Promise(async (resolve: any, reject: any) => {
|
|
42
|
+
try {
|
|
43
|
+
await callback(...args);
|
|
44
|
+
return resolve();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return reject(e);
|
|
47
|
+
}
|
|
48
|
+
}).timeout(timeout, timeoutMessage);
|
|
49
|
+
};
|
|
50
|
+
|
|
40
51
|
const connectionCreatedConst = 'connectionCreated';
|
|
41
52
|
class RabbitMq implements IAfRabbitMq {
|
|
42
53
|
static parseMsg(msg: any) {
|
|
@@ -216,6 +227,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
216
227
|
queue,
|
|
217
228
|
(msg: any) => {
|
|
218
229
|
newTrace(traceTypes.RABBIT);
|
|
230
|
+
if (optionsWithDefaults.timeout) {
|
|
231
|
+
const args = [
|
|
232
|
+
RabbitMq.parseMsg(msg),
|
|
233
|
+
this.ack(channel),
|
|
234
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
235
|
+
];
|
|
236
|
+
callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
|
|
237
|
+
}
|
|
219
238
|
callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
220
239
|
},
|
|
221
240
|
),
|