@autofleet/rabbit 2.1.12 → 2.1.14
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 +5 -1
- package/dist/index.js +9 -3
- package/package.json +1 -1
- package/src/index.ts +14 -3
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export interface IAfRabbitMq {
|
|
|
18
18
|
interface ExchangesCache {
|
|
19
19
|
[key: string]: any;
|
|
20
20
|
}
|
|
21
|
+
interface QueuesCache {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
21
24
|
declare type CustomMessageHeaders = {
|
|
22
25
|
redisTimestampValidationKey?: string;
|
|
23
26
|
};
|
|
@@ -40,6 +43,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
40
43
|
em: EventEmitter;
|
|
41
44
|
creatingConnection: boolean;
|
|
42
45
|
exchanges: ExchangesCache;
|
|
46
|
+
queues: QueuesCache;
|
|
43
47
|
options: AfRabbitOptions | undefined;
|
|
44
48
|
redisClient: any;
|
|
45
49
|
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig);
|
|
@@ -52,7 +56,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
52
56
|
assertExchange(exchangeName: string, options?: any): Promise<any>;
|
|
53
57
|
getQueueLength(queue: string): Promise<import("amqplib").Replies.AssertQueue>;
|
|
54
58
|
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
55
|
-
assertQueue(
|
|
59
|
+
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<any>;
|
|
56
60
|
consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
57
61
|
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
58
62
|
publish(exchange: string, content: any, customHeaders?: any): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -76,6 +76,7 @@ class RabbitMq {
|
|
|
76
76
|
this.connection = null;
|
|
77
77
|
this.creatingConnection = false;
|
|
78
78
|
this.exchanges = {};
|
|
79
|
+
this.queues = {};
|
|
79
80
|
this.options = options;
|
|
80
81
|
this.redisClient = redisConfig && redis_1.default(redisConfig);
|
|
81
82
|
}
|
|
@@ -182,11 +183,16 @@ class RabbitMq {
|
|
|
182
183
|
return channel.bindQueue(queue, exchange, '');
|
|
183
184
|
});
|
|
184
185
|
}
|
|
185
|
-
assertQueue(
|
|
186
|
+
assertQueue(queueName, options) {
|
|
186
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
RabbitMq.validateName('queue',
|
|
188
|
+
RabbitMq.validateName('queue', queueName);
|
|
188
189
|
const channel = yield this.assertChannel();
|
|
189
|
-
|
|
190
|
+
if (this.queues[queueName]) {
|
|
191
|
+
return this.queues[queueName];
|
|
192
|
+
}
|
|
193
|
+
const queue = yield channel.assertQueue(queueName, options);
|
|
194
|
+
this.queues[queueName] = queueName;
|
|
195
|
+
return queue;
|
|
190
196
|
});
|
|
191
197
|
}
|
|
192
198
|
consume(queue, callback, options) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,6 +25,9 @@ export interface IAfRabbitMq {
|
|
|
25
25
|
interface ExchangesCache {
|
|
26
26
|
[key: string]: any
|
|
27
27
|
}
|
|
28
|
+
interface QueuesCache {
|
|
29
|
+
[key: string]: any
|
|
30
|
+
}
|
|
28
31
|
|
|
29
32
|
type CustomMessageHeaders = {
|
|
30
33
|
redisTimestampValidationKey?: string;
|
|
@@ -92,6 +95,8 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
92
95
|
|
|
93
96
|
exchanges: ExchangesCache;
|
|
94
97
|
|
|
98
|
+
queues: QueuesCache;
|
|
99
|
+
|
|
95
100
|
options: AfRabbitOptions | undefined;
|
|
96
101
|
|
|
97
102
|
redisClient: any;
|
|
@@ -102,6 +107,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
102
107
|
this.connection = null;
|
|
103
108
|
this.creatingConnection = false;
|
|
104
109
|
this.exchanges = {};
|
|
110
|
+
this.queues = {};
|
|
105
111
|
this.options = options;
|
|
106
112
|
this.redisClient = redisConfig && getRedisInstance(redisConfig);
|
|
107
113
|
}
|
|
@@ -231,10 +237,15 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
231
237
|
return channel.bindQueue(queue, exchange, '');
|
|
232
238
|
}
|
|
233
239
|
|
|
234
|
-
async assertQueue(
|
|
235
|
-
RabbitMq.validateName('queue',
|
|
240
|
+
async assertQueue(queueName: string, options?: Options.AssertQueue) {
|
|
241
|
+
RabbitMq.validateName('queue', queueName);
|
|
236
242
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
237
|
-
|
|
243
|
+
if (this.queues[queueName]) {
|
|
244
|
+
return this.queues[queueName];
|
|
245
|
+
}
|
|
246
|
+
const queue = await channel.assertQueue(queueName, options);
|
|
247
|
+
this.queues[queueName] = queueName;
|
|
248
|
+
return queue;
|
|
238
249
|
}
|
|
239
250
|
|
|
240
251
|
async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
|