@autofleet/rabbit 1.0.15 → 1.0.17

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
@@ -26,12 +26,6 @@ class RabbitMq {
26
26
  this.em = new events_1.EventEmitter;
27
27
  this.channel = null;
28
28
  this.connection = null;
29
- process.once('SIGINT', () => {
30
- console.log('Removing channel');
31
- if (this.channel) {
32
- this.channel.close();
33
- }
34
- });
35
29
  }
36
30
  async getConnection() {
37
31
  if (this.connection !== null) {
@@ -70,35 +64,31 @@ class RabbitMq {
70
64
  const channel = await this.assertChannel();
71
65
  return channel.addSetup((c) => c.assertQueue(queue));
72
66
  }
73
- async consume(queue, callback, options, isFirstTime = true) {
67
+ async consume(queue, callback, options) {
74
68
  const { limit } = options ? options : 1;
75
69
  const channel = await this.assertChannel();
76
70
  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
- }
71
+ return channel.addSetup((c) => {
72
+ return Promise.all([
73
+ c.prefetch(limit, false),
74
+ c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
75
+ ]);
76
+ });
85
77
  }
86
- async consumeFromExchange(queue, exchange, callback, options, isFirstTime = true) {
78
+ async consumeFromExchange(queue, exchange, callback, options) {
87
79
  const { limit } = options ? options : 1;
88
80
  const channel = await this.assertChannel();
89
81
  await Promise.all([
90
82
  this.assertExchange(exchange),
91
83
  this.assertQueue(queue),
92
84
  ]);
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
- }
85
+ return channel.addSetup((c) => {
86
+ return Promise.all([
87
+ c.prefetch(limit, false),
88
+ c.bindQueue(queue, exchange, ''),
89
+ c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
90
+ ]);
91
+ });
102
92
  }
103
93
  async publish(exchange, content) {
104
94
  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.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -11,12 +11,6 @@ class RabbitMq {
11
11
  this.em = new EventEmitter;
12
12
  this.channel = null;
13
13
  this.connection = null;
14
- process.once('SIGINT', () => {
15
- console.log('Removing channel');
16
- if(this.channel) {
17
- this.channel.close();
18
- }
19
- });
20
14
  }
21
15
 
22
16
  public ack = async (msg: any) => {
@@ -82,36 +76,33 @@ class RabbitMq {
82
76
  return channel.addSetup((c: ConfirmChannel) => c.assertQueue(queue));
83
77
  }
84
78
 
85
- async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime: boolean = true) {
79
+ async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
86
80
  const { limit } = options ? options : 1;
87
81
  const channel: ChannelWrapper = await this.assertChannel();
88
82
  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
- }
83
+ return channel.addSetup((c: ConfirmChannel) => {
84
+ return Promise.all([
85
+ c.prefetch(limit, false),
86
+ c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
87
+ ]);
88
+ });
97
89
  }
98
90
 
99
- async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any, isFirstTime: boolean = true) {
91
+ async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
100
92
  const { limit } = options ? options : 1;
101
93
  const channel: ChannelWrapper = await this.assertChannel();
102
94
  await Promise.all([
103
95
  this.assertExchange(exchange),
104
96
  this.assertQueue(queue),
105
97
  ]);
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
- }
98
+
99
+ return channel.addSetup((c: ConfirmChannel) => {
100
+ return Promise.all([
101
+ c.prefetch(limit, false),
102
+ c.bindQueue(queue, exchange, ''),
103
+ c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
104
+ ])
105
+ })
115
106
  }
116
107
 
117
108
  async publish(exchange: string, content: any) {