@autofleet/rabbit 3.2.19-beta.7 → 3.2.19-beta.8
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.js +25 -10
- package/package.json +1 -1
- package/src/index.ts +23 -10
package/dist/index.js
CHANGED
|
@@ -147,7 +147,7 @@ class RabbitMq {
|
|
|
147
147
|
}
|
|
148
148
|
async getConnection(connectionRole) {
|
|
149
149
|
return new Promise(async (resolve, reject) => {
|
|
150
|
-
|
|
150
|
+
const { connectionByRole, creatingConnectionByRole } = this.geConnectionByRole(connectionRole);
|
|
151
151
|
if (this.blockReconnect) {
|
|
152
152
|
debug('rabbit: block reconnect');
|
|
153
153
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -169,7 +169,12 @@ class RabbitMq {
|
|
|
169
169
|
this.em.once(consts_1.CONNECTION_FAILED_CONST, reject);
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
if (connectionRole === types_1.ConnectionRole.Consumer) {
|
|
173
|
+
this.creatingConsumeConnection = true;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.creatingPublishConnection = true;
|
|
177
|
+
}
|
|
173
178
|
let isResolved = false;
|
|
174
179
|
// It is import to use it as a function and not as a variable
|
|
175
180
|
// because of k8s changes the env variables
|
|
@@ -189,8 +194,13 @@ class RabbitMq {
|
|
|
189
194
|
logger_1.default.error('rabbit: couldnt create a connection');
|
|
190
195
|
return resolve(connectionByRole);
|
|
191
196
|
}
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
if (connectionRole === types_1.ConnectionRole.Consumer) {
|
|
198
|
+
this.consumeConnection = newConnection;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.publishConnection = newConnection;
|
|
202
|
+
}
|
|
203
|
+
newConnection.on('error', (err) => {
|
|
194
204
|
logger_1.default.error('rabbit: connection error', { err });
|
|
195
205
|
if (!isResolved) {
|
|
196
206
|
isResolved = true;
|
|
@@ -198,7 +208,7 @@ class RabbitMq {
|
|
|
198
208
|
this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
|
|
199
209
|
}
|
|
200
210
|
});
|
|
201
|
-
|
|
211
|
+
newConnection.on('connectFailed', (err) => {
|
|
202
212
|
this.consumersTags = [];
|
|
203
213
|
logger_1.default.error('rabbit: connection connectFailed', { err });
|
|
204
214
|
if (!isResolved) {
|
|
@@ -207,7 +217,7 @@ class RabbitMq {
|
|
|
207
217
|
this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
|
|
208
218
|
}
|
|
209
219
|
});
|
|
210
|
-
|
|
220
|
+
newConnection.on('disconnect', ({ err }) => {
|
|
211
221
|
this.consumersTags = [];
|
|
212
222
|
debug('rabbit: connection closed');
|
|
213
223
|
if (this.options?.disableReconnect) {
|
|
@@ -218,12 +228,17 @@ class RabbitMq {
|
|
|
218
228
|
logger_1.default.error(`${this.RECONNECT_MSG}${err && ` - ${err}`}`);
|
|
219
229
|
}
|
|
220
230
|
});
|
|
221
|
-
|
|
231
|
+
newConnection.once('connect', async () => {
|
|
222
232
|
debug('rabbit: connection established');
|
|
223
|
-
|
|
224
|
-
|
|
233
|
+
if (connectionRole === types_1.ConnectionRole.Consumer) {
|
|
234
|
+
this.creatingConsumeConnection = false;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
this.creatingPublishConnection = false;
|
|
238
|
+
}
|
|
239
|
+
this.em.emit(consts_1.CONNECTION_CREATED_CONST, newConnection);
|
|
225
240
|
isResolved = true;
|
|
226
|
-
resolve(
|
|
241
|
+
resolve(newConnection);
|
|
227
242
|
});
|
|
228
243
|
});
|
|
229
244
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -284,7 +284,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
284
284
|
|
|
285
285
|
async getConnection(connectionRole: ConnectionRole) {
|
|
286
286
|
return new Promise<AmqpConnectionManager | undefined | null>(async (resolve, reject) => {
|
|
287
|
-
|
|
287
|
+
const { connectionByRole, creatingConnectionByRole } = this.geConnectionByRole(connectionRole);
|
|
288
288
|
if (this.blockReconnect) {
|
|
289
289
|
debug('rabbit: block reconnect');
|
|
290
290
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -306,7 +306,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
306
306
|
this.em.once(CONNECTION_FAILED_CONST, reject);
|
|
307
307
|
return;
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
if (connectionRole === ConnectionRole.Consumer) {
|
|
310
|
+
this.creatingConsumeConnection = true;
|
|
311
|
+
} else {
|
|
312
|
+
this.creatingPublishConnection = true;
|
|
313
|
+
}
|
|
314
|
+
|
|
310
315
|
let isResolved = false;
|
|
311
316
|
|
|
312
317
|
// It is import to use it as a function and not as a variable
|
|
@@ -332,9 +337,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
332
337
|
return resolve(connectionByRole);
|
|
333
338
|
}
|
|
334
339
|
|
|
335
|
-
|
|
340
|
+
if (connectionRole === ConnectionRole.Consumer) {
|
|
341
|
+
this.consumeConnection = newConnection;
|
|
342
|
+
} else {
|
|
343
|
+
this.publishConnection = newConnection;
|
|
344
|
+
}
|
|
336
345
|
|
|
337
|
-
|
|
346
|
+
newConnection.on('error', (err) => {
|
|
338
347
|
logger.error('rabbit: connection error', { err });
|
|
339
348
|
if (!isResolved) {
|
|
340
349
|
isResolved = true;
|
|
@@ -343,7 +352,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
343
352
|
}
|
|
344
353
|
});
|
|
345
354
|
|
|
346
|
-
|
|
355
|
+
newConnection.on('connectFailed', (err) => {
|
|
347
356
|
this.consumersTags = [];
|
|
348
357
|
logger.error('rabbit: connection connectFailed', { err });
|
|
349
358
|
if (!isResolved) {
|
|
@@ -353,7 +362,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
353
362
|
}
|
|
354
363
|
});
|
|
355
364
|
|
|
356
|
-
|
|
365
|
+
newConnection.on('disconnect', ({ err }) => {
|
|
357
366
|
this.consumersTags = [];
|
|
358
367
|
debug('rabbit: connection closed');
|
|
359
368
|
if (this.options?.disableReconnect) {
|
|
@@ -363,12 +372,16 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
363
372
|
logger.error(`${this.RECONNECT_MSG}${err && ` - ${err}`}`);
|
|
364
373
|
}
|
|
365
374
|
});
|
|
366
|
-
|
|
375
|
+
newConnection.once('connect', async () => {
|
|
367
376
|
debug('rabbit: connection established');
|
|
368
|
-
|
|
369
|
-
|
|
377
|
+
if (connectionRole === ConnectionRole.Consumer) {
|
|
378
|
+
this.creatingConsumeConnection = false;
|
|
379
|
+
} else {
|
|
380
|
+
this.creatingPublishConnection = false;
|
|
381
|
+
}
|
|
382
|
+
this.em.emit(CONNECTION_CREATED_CONST, newConnection);
|
|
370
383
|
isResolved = true;
|
|
371
|
-
resolve(
|
|
384
|
+
resolve(newConnection);
|
|
372
385
|
});
|
|
373
386
|
});
|
|
374
387
|
}
|