@autofleet/rabbit 2.0.4-alpha → 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/dist/index.js CHANGED
@@ -72,6 +72,7 @@ class RabbitMq {
72
72
  && (!msg.content['x-retry-count']
73
73
  || msg.content['x-retry-count'] < options.retries)) {
74
74
  msg.content['x-retry-count'] = msg.content['x-retry-count'] ? msg.content['x-retry-count'] + 1 : 1;
75
+ // msg.content.nackCount = msg.content.nackCount ? msg.content.nackCount + 1 : 1;
75
76
  yield this.sendToQueue(queue, msg.content);
76
77
  }
77
78
  else {
@@ -213,7 +214,9 @@ class RabbitMq {
213
214
  ];
214
215
  callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
215
216
  }
216
- callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
217
+ else {
218
+ callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
219
+ }
217
220
  }),
218
221
  ]);
219
222
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.0.4-alpha",
3
+ "version": "2.0.4-beta1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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
- 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
- };
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 {
@@ -121,6 +119,7 @@ class RabbitMq implements IAfRabbitMq {
121
119
  || msg.content['x-retry-count'] < options.retries)
122
120
  ) {
123
121
  msg.content['x-retry-count'] = msg.content['x-retry-count'] ? msg.content['x-retry-count'] + 1 : 1;
122
+ // msg.content.nackCount = msg.content.nackCount ? msg.content.nackCount + 1 : 1;
124
123
  await this.sendToQueue(queue, msg.content);
125
124
  } else {
126
125
  const deadQueue = `${queue}-dead`;
@@ -225,7 +224,7 @@ class RabbitMq implements IAfRabbitMq {
225
224
  return Promise.all([
226
225
  c.consume(
227
226
  queue,
228
- (msg: any) => {
227
+ async (msg: any) => {
229
228
  newTrace(traceTypes.RABBIT);
230
229
  if (optionsWithDefaults.timeout) {
231
230
  const args = [
@@ -233,9 +232,14 @@ class RabbitMq implements IAfRabbitMq {
233
232
  this.ack(channel),
234
233
  this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
235
234
  ];
236
- callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
235
+ try {
236
+ await callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
237
+ } catch (e) {
238
+ this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
239
+ }
240
+ } else {
241
+ callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
237
242
  }
238
- callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
239
243
  },
240
244
  ),
241
245
  ]);