@autofleet/rabbit 2.0.2 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.0.2",
3
+ "version": "2.0.4-alpha",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -15,7 +15,6 @@
15
15
  "dev": "nodemon"
16
16
  },
17
17
  "dependencies": {
18
- "@autofleet/outbreak": "0.0.6",
19
18
  "@types/amqp-connection-manager": "^2.0.10",
20
19
  "@types/amqplib": "^0.5.16",
21
20
  "amqp-connection-manager": "^3.2.1",
@@ -23,6 +22,7 @@
23
22
  "bluebird": "^3.7.2"
24
23
  },
25
24
  "devDependencies": {
25
+ "@autofleet/outbreak": "*",
26
26
  "@types/jest": "^26.0.23",
27
27
  "@typescript-eslint/eslint-plugin": "^4.8.1",
28
28
  "eslint": "^7.13.0",
@@ -34,5 +34,8 @@
34
34
  "typescript": "^3.8.3"
35
35
  },
36
36
  "author": "",
37
- "license": "ISC"
37
+ "license": "ISC",
38
+ "peerDependencies": {
39
+ "@autofleet/outbreak": "^0.1.1"
40
+ }
38
41
  }
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
  ),