@autofleet/rabbit 1.6.1 → 1.6.2

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.d.ts CHANGED
@@ -23,7 +23,7 @@ declare class RabbitMq {
23
23
  options: AfRabbitOptions | undefined;
24
24
  constructor(options?: AfRabbitOptions);
25
25
  ack: (msg: any) => Promise<void>;
26
- nack: (queue: string, options: any, deadQueueOptions: Options.AssertQueue) => (msg: any) => Promise<void>;
26
+ nack: (queue: string, options: any, deadQueueOptions: Options.AssertQueue) => (msg: any, { skipRetry, }?: any) => Promise<void>;
27
27
  getConnection(): Promise<AmqpConnectionManager>;
28
28
  assertChannel(): Promise<ChannelWrapper>;
29
29
  assertExchange(exchangeName: string, options?: any): Promise<any>;
package/dist/index.js CHANGED
@@ -57,9 +57,11 @@ class RabbitMq {
57
57
  yield this.channel.ack(msg);
58
58
  }
59
59
  });
60
- this.nack = (queue, options, deadQueueOptions) => (msg) => __awaiter(this, void 0, void 0, function* () {
60
+ this.nack = (queue, options, deadQueueOptions) => (msg, { skipRetry = false, } = {}) => __awaiter(this, void 0, void 0, function* () {
61
61
  if (this.channel) {
62
- if (!msg.content['x-retry-count'] || msg.content['x-retry-count'] < options.retries) {
62
+ if (!skipRetry
63
+ && (!msg.content['x-retry-count']
64
+ || msg.content['x-retry-count'] < options.retries)) {
63
65
  msg.content['x-retry-count'] = msg.content['x-retry-count'] ? msg.content['x-retry-count'] + 1 : 1;
64
66
  yield this.sendToQueue(queue, msg.content);
65
67
  }
@@ -21,10 +21,15 @@ const callback = (eq = 'hey') => (msg, ack) => {
21
21
  expect(msg.content).toEqual(eq);
22
22
  ack(msg);
23
23
  };
24
- const nackcallback = () => (msg, ack, nack) => {
24
+ const nackcallback = ({ skipRetry = false } = {}) => (msg, ack, nack) => {
25
25
  console.log('msg', msg.content);
26
26
  expect(msg.content.ttt).toEqual('hey-q');
27
- nack(msg);
27
+ if (skipRetry) {
28
+ nack(msg, { skipRetry });
29
+ }
30
+ else {
31
+ nack(msg);
32
+ }
28
33
  };
29
34
  describe('RabbitMQ', () => {
30
35
  it('check exchange', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -48,6 +53,13 @@ describe('RabbitMQ', () => {
48
53
  yield delay(1500);
49
54
  expect(mockFn).toHaveBeenCalledTimes(4); // one run then 3 times retry
50
55
  }));
56
+ it('check skip retry', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const mockFn = jest.fn(nackcallback({ skipRetry: true }));
58
+ yield rabbit.consume('test-q-skip-retry', mockFn, { retries: 3 });
59
+ yield rabbit.sendToQueue('test-q-skip-retry', { ttt: 'hey-q' });
60
+ yield delay(1500);
61
+ expect(mockFn).toHaveBeenCalledTimes(1);
62
+ }));
51
63
  it('check nack and dead queue', () => __awaiter(void 0, void 0, void 0, function* () {
52
64
  const mockFn = jest.fn(nackcallback());
53
65
  yield rabbit.consume('test-q-nack', mockFn);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.test.ts CHANGED
@@ -12,10 +12,14 @@ const callback = (eq = 'hey') => (msg: any, ack: any) => {
12
12
  ack(msg);
13
13
  };
14
14
 
15
- const nackcallback = () => (msg: any, ack: any, nack: any) => {
15
+ const nackcallback = ({ skipRetry = false } = { }) => (msg: any, ack: any, nack: any) => {
16
16
  console.log('msg', msg.content);
17
17
  expect(msg.content.ttt).toEqual('hey-q');
18
- nack(msg);
18
+ if (skipRetry) {
19
+ nack(msg, { skipRetry });
20
+ } else {
21
+ nack(msg);
22
+ }
19
23
  };
20
24
 
21
25
  describe('RabbitMQ', () => {
@@ -43,6 +47,14 @@ describe('RabbitMQ', () => {
43
47
  expect(mockFn).toHaveBeenCalledTimes(4); // one run then 3 times retry
44
48
  });
45
49
 
50
+ it('check skip retry', async () => {
51
+ const mockFn = jest.fn(nackcallback({ skipRetry: true }));
52
+ await rabbit.consume('test-q-skip-retry', mockFn, { retries: 3 });
53
+ await rabbit.sendToQueue('test-q-skip-retry', { ttt: 'hey-q' });
54
+ await delay(1500);
55
+ expect(mockFn).toHaveBeenCalledTimes(1);
56
+ });
57
+
46
58
  it('check nack and dead queue', async () => {
47
59
  const mockFn = jest.fn(nackcallback());
48
60
  await rabbit.consume('test-q-nack', mockFn);
package/src/index.ts CHANGED
@@ -82,9 +82,22 @@ class RabbitMq {
82
82
  }
83
83
  }
84
84
 
85
- public nack = (queue: string, options: any, deadQueueOptions: Options.AssertQueue) => async (msg: any) => {
85
+ public nack = (
86
+ queue: string,
87
+ options: any,
88
+ deadQueueOptions: Options.AssertQueue,
89
+ ) => async (
90
+ msg: any,
91
+ {
92
+ skipRetry = false,
93
+ }: any = { },
94
+ ) => {
86
95
  if (this.channel) {
87
- if (!msg.content['x-retry-count'] || msg.content['x-retry-count'] < options.retries) {
96
+ if (
97
+ !skipRetry
98
+ && (!msg.content['x-retry-count']
99
+ || msg.content['x-retry-count'] < options.retries)
100
+ ) {
88
101
  msg.content['x-retry-count'] = msg.content['x-retry-count'] ? msg.content['x-retry-count'] + 1 : 1;
89
102
  await this.sendToQueue(queue, msg.content);
90
103
  } else {