@autofleet/rabbit 1.0.15 → 1.0.16

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
@@ -12,8 +12,8 @@ declare class RabbitMq {
12
12
  assertChannel(): Promise<ChannelWrapper>;
13
13
  assertExchange(exchange: string, options?: any): Promise<void>;
14
14
  assertQueue(queue: string, options?: any): Promise<void>;
15
- consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime?: boolean): Promise<void>;
16
- consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime?: boolean): Promise<void>;
15
+ consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
16
+ consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
17
17
  publish(exchange: string, content: any): Promise<void>;
18
18
  sendToQueue(queue: string, content: any): Promise<void>;
19
19
  }
package/dist/index.js CHANGED
@@ -70,35 +70,31 @@ class RabbitMq {
70
70
  const channel = await this.assertChannel();
71
71
  return channel.addSetup((c) => c.assertQueue(queue));
72
72
  }
73
- async consume(queue, callback, options, isFirstTime = true) {
73
+ async consume(queue, callback, options) {
74
74
  const { limit } = options ? options : 1;
75
75
  const channel = await this.assertChannel();
76
76
  await this.assertQueue(queue);
77
- if (!isFirstTime) {
78
- return channel.addSetup((c) => {
79
- return Promise.all([
80
- c.prefetch(limit, false),
81
- c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
82
- ]);
83
- });
84
- }
77
+ return channel.addSetup((c) => {
78
+ return Promise.all([
79
+ c.prefetch(limit, false),
80
+ c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
81
+ ]);
82
+ });
85
83
  }
86
- async consumeFromExchange(queue, exchange, callback, options, isFirstTime = true) {
84
+ async consumeFromExchange(queue, exchange, callback, options) {
87
85
  const { limit } = options ? options : 1;
88
86
  const channel = await this.assertChannel();
89
87
  await Promise.all([
90
88
  this.assertExchange(exchange),
91
89
  this.assertQueue(queue),
92
90
  ]);
93
- if (!isFirstTime) {
94
- return channel.addSetup((c) => {
95
- return Promise.all([
96
- c.prefetch(limit, false),
97
- c.bindQueue(queue, exchange, ''),
98
- c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
99
- ]);
100
- });
101
- }
91
+ return channel.addSetup((c) => {
92
+ return Promise.all([
93
+ c.prefetch(limit, false),
94
+ c.bindQueue(queue, exchange, ''),
95
+ c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
96
+ ]);
97
+ });
102
98
  }
103
99
  async publish(exchange, content) {
104
100
  const channel = await this.assertChannel();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -82,36 +82,33 @@ class RabbitMq {
82
82
  return channel.addSetup((c: ConfirmChannel) => c.assertQueue(queue));
83
83
  }
84
84
 
85
- async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime: boolean = true) {
85
+ async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
86
86
  const { limit } = options ? options : 1;
87
87
  const channel: ChannelWrapper = await this.assertChannel();
88
88
  await this.assertQueue(queue);
89
- if (!isFirstTime) {
90
- return channel.addSetup((c: ConfirmChannel) => {
91
- return Promise.all([
92
- c.prefetch(limit, false),
93
- c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
94
- ]);
95
- });
96
- }
89
+ return channel.addSetup((c: ConfirmChannel) => {
90
+ return Promise.all([
91
+ c.prefetch(limit, false),
92
+ c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
93
+ ]);
94
+ });
97
95
  }
98
96
 
99
- async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime: boolean = true) {
97
+ async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
100
98
  const { limit } = options ? options : 1;
101
99
  const channel: ChannelWrapper = await this.assertChannel();
102
100
  await Promise.all([
103
101
  this.assertExchange(exchange),
104
102
  this.assertQueue(queue),
105
103
  ]);
106
- if (!isFirstTime) {
107
- return channel.addSetup((c: ConfirmChannel) => {
108
- return Promise.all([
109
- c.prefetch(limit, false),
110
- c.bindQueue(queue, exchange, ''),
111
- c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
112
- ])
113
- })
114
- }
104
+
105
+ return channel.addSetup((c: ConfirmChannel) => {
106
+ return Promise.all([
107
+ c.prefetch(limit, false),
108
+ c.bindQueue(queue, exchange, ''),
109
+ c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
110
+ ])
111
+ })
115
112
  }
116
113
 
117
114
  async publish(exchange: string, content: any) {