@autofleet/rabbit 1.3.2 → 1.3.3

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
@@ -4,9 +4,6 @@ import { EventEmitter } from 'events';
4
4
  interface ExchangesCache {
5
5
  [key: string]: any;
6
6
  }
7
- interface QueuesCache {
8
- [key: string]: any;
9
- }
10
7
  declare class RabbitMq {
11
8
  static parseMsg(msg: any): any;
12
9
  channel: ChannelWrapper | null;
@@ -14,14 +11,13 @@ declare class RabbitMq {
14
11
  em: EventEmitter;
15
12
  creatingConnection: Boolean;
16
13
  exchanges: ExchangesCache;
17
- queues: QueuesCache;
18
14
  constructor();
19
15
  ack: (msg: any) => Promise<void>;
20
16
  nack: (queue: string) => (msg: any, retries: number) => Promise<void>;
21
17
  getConnection(): Promise<AmqpConnectionManager>;
22
18
  assertChannel(): Promise<ChannelWrapper>;
23
19
  assertExchange(exchangeName: string, options?: any): Promise<any>;
24
- assertQueue(queueName: string, options?: any): Promise<any>;
20
+ assertQueue(queue: string, options?: any): Promise<void>;
25
21
  consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
26
22
  consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
27
23
  publish(exchange: string, content: any): Promise<void>;
package/dist/index.js CHANGED
@@ -29,7 +29,6 @@ class RabbitMq {
29
29
  this.connection = null;
30
30
  this.creatingConnection = false;
31
31
  this.exchanges = {};
32
- this.queues = {};
33
32
  }
34
33
  static parseMsg(msg) {
35
34
  let { content } = msg;
@@ -86,16 +85,9 @@ class RabbitMq {
86
85
  return exchange;
87
86
  });
88
87
  }
89
- async assertQueue(queueName, options) {
88
+ async assertQueue(queue, options) {
90
89
  const channel = await this.assertChannel();
91
- if (this.queues[queueName]) {
92
- return this.queues[queueName];
93
- }
94
- return channel.addSetup(async (c) => {
95
- const queue = await c.assertQueue(queueName);
96
- this.queues[queueName] = queue;
97
- return queue;
98
- });
90
+ return channel.addSetup((c) => c.assertQueue(queue));
99
91
  }
100
92
  async consume(queue, callback, options) {
101
93
  const { limit } = (options && options.limit) ? options : { limit: 1 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "@types/amqp-connection-manager": "^2.0.2",
14
14
  "@types/amqplib": "^0.5.9",
15
15
  "@types/jest": "^23.3.10",
16
- "amqp-connection-manager": "^2.3.0",
16
+ "amqp-connection-manager": "^3.2.0",
17
17
  "amqplib": "^0.5.3",
18
18
  "jest": "^23.6.0"
19
19
  },
package/src/index.ts CHANGED
@@ -6,10 +6,6 @@ interface ExchangesCache {
6
6
  [key: string]: any
7
7
  }
8
8
 
9
- interface QueuesCache {
10
- [key: string]: any
11
- }
12
-
13
9
  const connectionCreatedConst = 'connectionCreated';
14
10
  class RabbitMq {
15
11
  static parseMsg(msg: any) {
@@ -31,7 +27,6 @@ class RabbitMq {
31
27
  em: EventEmitter;
32
28
  creatingConnection: Boolean;
33
29
  exchanges: ExchangesCache;
34
- queues: QueuesCache;
35
30
 
36
31
  constructor() {
37
32
  this.em = new EventEmitter;
@@ -39,7 +34,6 @@ class RabbitMq {
39
34
  this.connection = null;
40
35
  this.creatingConnection = false;
41
36
  this.exchanges = {};
42
- this.queues = {};
43
37
  }
44
38
 
45
39
  public ack = async (msg: any) => {
@@ -112,16 +106,9 @@ class RabbitMq {
112
106
  });
113
107
  }
114
108
 
115
- async assertQueue(queueName: string, options?: any) {
109
+ async assertQueue(queue: string, options?: any) {
116
110
  const channel: ChannelWrapper = await this.assertChannel();
117
- if(this.queues[queueName]) {
118
- return this.queues[queueName]
119
- }
120
- return channel.addSetup(async (c: ConfirmChannel) => {
121
- const queue = await c.assertQueue(queueName)
122
- this.queues[queueName] = queue;
123
- return queue;
124
- });
111
+ return channel.addSetup((c: ConfirmChannel) => c.assertQueue(queue));
125
112
  }
126
113
 
127
114
  async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {