@autofleet/rabbit 2.1.13 → 2.1.15
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 +1 -1
- package/dist/index.js +9 -5
- package/package.json +1 -1
- package/src/index.ts +9 -5
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
56
56
|
assertExchange(exchangeName: string, options?: any): Promise<any>;
|
|
57
57
|
getQueueLength(queue: string): Promise<import("amqplib").Replies.AssertQueue>;
|
|
58
58
|
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
59
|
-
assertQueue(
|
|
59
|
+
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<any>;
|
|
60
60
|
consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
61
61
|
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
62
62
|
publish(exchange: string, content: any, customHeaders?: any): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -118,6 +118,8 @@ class RabbitMq {
|
|
|
118
118
|
this.connection = connection;
|
|
119
119
|
this.connection.on('disconnect', ({ err }) => {
|
|
120
120
|
var _a;
|
|
121
|
+
this.exchanges = {};
|
|
122
|
+
this.queues = {};
|
|
121
123
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.reconnect) {
|
|
122
124
|
console.error(`${this.RESCONNECT_MSG}${err && ` - ${err}`}`);
|
|
123
125
|
this.connection = null;
|
|
@@ -183,14 +185,16 @@ class RabbitMq {
|
|
|
183
185
|
return channel.bindQueue(queue, exchange, '');
|
|
184
186
|
});
|
|
185
187
|
}
|
|
186
|
-
assertQueue(
|
|
188
|
+
assertQueue(queueName, options) {
|
|
187
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
RabbitMq.validateName('queue',
|
|
190
|
+
RabbitMq.validateName('queue', queueName);
|
|
189
191
|
const channel = yield this.assertChannel();
|
|
190
|
-
if (this.queues[
|
|
191
|
-
return this.queues[
|
|
192
|
+
if (this.queues[queueName]) {
|
|
193
|
+
return this.queues[queueName];
|
|
192
194
|
}
|
|
193
|
-
|
|
195
|
+
const queue = yield channel.assertQueue(queueName, options);
|
|
196
|
+
this.queues[queueName] = queueName;
|
|
197
|
+
return queue;
|
|
194
198
|
});
|
|
195
199
|
}
|
|
196
200
|
consume(queue, callback, options) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -178,6 +178,8 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
178
178
|
this.connection = connection;
|
|
179
179
|
this.connection.on('disconnect',
|
|
180
180
|
({ err }) => {
|
|
181
|
+
this.exchanges = {};
|
|
182
|
+
this.queues = {};
|
|
181
183
|
if (this.options?.reconnect) {
|
|
182
184
|
console.error(`${this.RESCONNECT_MSG}${err && ` - ${err}`}`);
|
|
183
185
|
this.connection = null;
|
|
@@ -237,13 +239,15 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
237
239
|
return channel.bindQueue(queue, exchange, '');
|
|
238
240
|
}
|
|
239
241
|
|
|
240
|
-
async assertQueue(
|
|
241
|
-
RabbitMq.validateName('queue',
|
|
242
|
+
async assertQueue(queueName: string, options?: Options.AssertQueue) {
|
|
243
|
+
RabbitMq.validateName('queue', queueName);
|
|
242
244
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
243
|
-
if (this.queues[
|
|
244
|
-
return this.queues[
|
|
245
|
+
if (this.queues[queueName]) {
|
|
246
|
+
return this.queues[queueName];
|
|
245
247
|
}
|
|
246
|
-
|
|
248
|
+
const queue = await channel.assertQueue(queueName, options);
|
|
249
|
+
this.queues[queueName] = queueName;
|
|
250
|
+
return queue;
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
|