@autofleet/rabbit 3.2.24-beta.2 → 3.2.24-beta.4
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 +21 -8
- package/dist/lib/consts.d.ts +0 -2
- package/dist/lib/consts.js +1 -3
- package/dist/lib/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/index.ts +26 -10
- package/src/lib/consts.ts +0 -2
- package/src/lib/types.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -120,8 +120,18 @@ class RabbitMq {
|
|
|
120
120
|
this.channel = null;
|
|
121
121
|
this.publishChannelSetupPromise = null;
|
|
122
122
|
this.connectionsMap = {
|
|
123
|
-
[consts_1.ConnectionPurpose.Consume]: {
|
|
124
|
-
|
|
123
|
+
[consts_1.ConnectionPurpose.Consume]: {
|
|
124
|
+
connection: null,
|
|
125
|
+
creatingConnection: false,
|
|
126
|
+
connectionCreatedEventName: 'consumeConnectionCreated',
|
|
127
|
+
connectionFailedEventName: 'consumeConnectionFailed',
|
|
128
|
+
},
|
|
129
|
+
[consts_1.ConnectionPurpose.Publish]: {
|
|
130
|
+
connection: null,
|
|
131
|
+
creatingConnection: false,
|
|
132
|
+
connectionCreatedEventName: 'publishConnectionCreated',
|
|
133
|
+
connectionFailedEventName: 'publishConnectionFailed',
|
|
134
|
+
},
|
|
125
135
|
};
|
|
126
136
|
this.exchanges = {};
|
|
127
137
|
this.queues = {};
|
|
@@ -146,7 +156,7 @@ class RabbitMq {
|
|
|
146
156
|
}
|
|
147
157
|
async getConnection(connectionPurpose) {
|
|
148
158
|
return new Promise(async (resolve, reject) => {
|
|
149
|
-
const { connection, creatingConnection } = this.connectionsMap[connectionPurpose];
|
|
159
|
+
const { connection, creatingConnection, connectionCreatedEventName, connectionFailedEventName, } = this.connectionsMap[connectionPurpose];
|
|
150
160
|
if (this.blockReconnect) {
|
|
151
161
|
debug('rabbit: block reconnect');
|
|
152
162
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -164,8 +174,8 @@ class RabbitMq {
|
|
|
164
174
|
}
|
|
165
175
|
if (creatingConnection) {
|
|
166
176
|
debug('rabbit: creating connection emi');
|
|
167
|
-
this.em.once(
|
|
168
|
-
this.em.once(
|
|
177
|
+
this.em.once(connectionCreatedEventName, resolve);
|
|
178
|
+
this.em.once(connectionFailedEventName, reject);
|
|
169
179
|
return;
|
|
170
180
|
}
|
|
171
181
|
this.connectionsMap[connectionPurpose].creatingConnection = true;
|
|
@@ -191,7 +201,7 @@ class RabbitMq {
|
|
|
191
201
|
if (!isResolved) {
|
|
192
202
|
isResolved = true;
|
|
193
203
|
reject(err);
|
|
194
|
-
this.em.emit(
|
|
204
|
+
this.em.emit(connectionFailedEventName, err);
|
|
195
205
|
}
|
|
196
206
|
});
|
|
197
207
|
newConnection.on('connectFailed', (err) => {
|
|
@@ -200,7 +210,7 @@ class RabbitMq {
|
|
|
200
210
|
if (!isResolved) {
|
|
201
211
|
isResolved = true;
|
|
202
212
|
reject(err);
|
|
203
|
-
this.em.emit(
|
|
213
|
+
this.em.emit(connectionFailedEventName, err);
|
|
204
214
|
}
|
|
205
215
|
});
|
|
206
216
|
newConnection.on('disconnect', ({ err }) => {
|
|
@@ -216,7 +226,7 @@ class RabbitMq {
|
|
|
216
226
|
});
|
|
217
227
|
newConnection.once('connect', async () => {
|
|
218
228
|
this.connectionsMap[connectionPurpose].creatingConnection = false;
|
|
219
|
-
this.em.emit(
|
|
229
|
+
this.em.emit(connectionCreatedEventName, newConnection);
|
|
220
230
|
isResolved = true;
|
|
221
231
|
resolve(newConnection);
|
|
222
232
|
});
|
|
@@ -507,6 +517,7 @@ class RabbitMq {
|
|
|
507
517
|
});
|
|
508
518
|
}
|
|
509
519
|
async publish(exchange, content, customHeaders) {
|
|
520
|
+
debug('rabbit: start publish msg');
|
|
510
521
|
return (0, utils_1.wrapSetImmediate)(async () => {
|
|
511
522
|
RabbitMq.validateName('exchange', exchange);
|
|
512
523
|
const channel = await this.assertChannel({ connectionPurpose: consts_1.ConnectionPurpose.Publish });
|
|
@@ -541,8 +552,10 @@ class RabbitMq {
|
|
|
541
552
|
}
|
|
542
553
|
}
|
|
543
554
|
async isConnected() {
|
|
555
|
+
debug('rabbit: start is connected');
|
|
544
556
|
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
545
557
|
const { connection } = connectionData;
|
|
558
|
+
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
546
559
|
if (connectionPurpose === consts_1.ConnectionPurpose.Publish && !connection) {
|
|
547
560
|
return true; // The connection hasn't been initialized yet, as no messages have been sent through it
|
|
548
561
|
}
|
package/dist/lib/consts.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ export declare const USER_TRACING_HEADER = "x-af-user-id";
|
|
|
6
6
|
export declare const AUTOMATION_ID_HEADER = "x-af-automation-id";
|
|
7
7
|
export declare const USER_OBJECT = "userObject";
|
|
8
8
|
export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
9
|
-
export declare const CONNECTION_CREATED_CONST = "connectionCreated";
|
|
10
|
-
export declare const CONNECTION_FAILED_CONST = "connectionFailed";
|
|
11
9
|
export declare const DEFAULT_OPTIONS: {
|
|
12
10
|
limit: number;
|
|
13
11
|
retries: number;
|
package/dist/lib/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionPurpose = exports.DEFAULT_OPTIONS = exports.
|
|
3
|
+
exports.ConnectionPurpose = exports.DEFAULT_OPTIONS = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = exports.AUTOMATION_ID_HEADER = exports.USER_TRACING_HEADER = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
|
|
4
4
|
exports.DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
|
|
5
5
|
exports.DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
6
6
|
exports.RETRY_HEADER = 'x-retry-count';
|
|
@@ -9,8 +9,6 @@ exports.USER_TRACING_HEADER = 'x-af-user-id';
|
|
|
9
9
|
exports.AUTOMATION_ID_HEADER = 'x-af-automation-id';
|
|
10
10
|
exports.USER_OBJECT = 'userObject';
|
|
11
11
|
exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
12
|
-
exports.CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
13
|
-
exports.CONNECTION_FAILED_CONST = 'connectionFailed';
|
|
14
12
|
exports.DEFAULT_OPTIONS = {
|
|
15
13
|
limit: 1,
|
|
16
14
|
retries: 1,
|
package/dist/lib/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,8 +20,6 @@ import getRedisInstance, { RedisConfig } from './lib/redis';
|
|
|
20
20
|
import { assertExchangeFanout, rand, wrapSetImmediate } from './lib/utils';
|
|
21
21
|
import {
|
|
22
22
|
AUTOMATION_ID_HEADER,
|
|
23
|
-
CONNECTION_CREATED_CONST,
|
|
24
|
-
CONNECTION_FAILED_CONST,
|
|
25
23
|
ConnectionPurpose,
|
|
26
24
|
DEFAULT_LOCK_TIMEOUT,
|
|
27
25
|
DEFAULT_OPTIONS,
|
|
@@ -183,8 +181,18 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
183
181
|
this.channel = null;
|
|
184
182
|
this.publishChannelSetupPromise = null;
|
|
185
183
|
this.connectionsMap = {
|
|
186
|
-
[ConnectionPurpose.Consume]: {
|
|
187
|
-
|
|
184
|
+
[ConnectionPurpose.Consume]: {
|
|
185
|
+
connection: null,
|
|
186
|
+
creatingConnection: false,
|
|
187
|
+
connectionCreatedEventName: 'consumeConnectionCreated',
|
|
188
|
+
connectionFailedEventName: 'consumeConnectionFailed',
|
|
189
|
+
},
|
|
190
|
+
[ConnectionPurpose.Publish]: {
|
|
191
|
+
connection: null,
|
|
192
|
+
creatingConnection: false,
|
|
193
|
+
connectionCreatedEventName: 'publishConnectionCreated',
|
|
194
|
+
connectionFailedEventName: 'publishConnectionFailed',
|
|
195
|
+
},
|
|
188
196
|
};
|
|
189
197
|
this.exchanges = {};
|
|
190
198
|
this.queues = {};
|
|
@@ -285,7 +293,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
285
293
|
|
|
286
294
|
async getConnection(connectionPurpose: ConnectionPurpose) {
|
|
287
295
|
return new Promise<AmqpConnectionManager | undefined | null>(async (resolve, reject) => {
|
|
288
|
-
const {
|
|
296
|
+
const {
|
|
297
|
+
connection,
|
|
298
|
+
creatingConnection,
|
|
299
|
+
connectionCreatedEventName,
|
|
300
|
+
connectionFailedEventName,
|
|
301
|
+
} = this.connectionsMap[connectionPurpose];
|
|
289
302
|
if (this.blockReconnect) {
|
|
290
303
|
debug('rabbit: block reconnect');
|
|
291
304
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -303,8 +316,8 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
303
316
|
}
|
|
304
317
|
if (creatingConnection) {
|
|
305
318
|
debug('rabbit: creating connection emi');
|
|
306
|
-
this.em.once(
|
|
307
|
-
this.em.once(
|
|
319
|
+
this.em.once(connectionCreatedEventName, resolve);
|
|
320
|
+
this.em.once(connectionFailedEventName, reject);
|
|
308
321
|
return;
|
|
309
322
|
}
|
|
310
323
|
this.connectionsMap[connectionPurpose].creatingConnection = true;
|
|
@@ -336,7 +349,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
336
349
|
if (!isResolved) {
|
|
337
350
|
isResolved = true;
|
|
338
351
|
reject(err);
|
|
339
|
-
this.em.emit(
|
|
352
|
+
this.em.emit(connectionFailedEventName, err);
|
|
340
353
|
}
|
|
341
354
|
});
|
|
342
355
|
|
|
@@ -346,7 +359,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
346
359
|
if (!isResolved) {
|
|
347
360
|
isResolved = true;
|
|
348
361
|
reject(err);
|
|
349
|
-
this.em.emit(
|
|
362
|
+
this.em.emit(connectionFailedEventName, err);
|
|
350
363
|
}
|
|
351
364
|
});
|
|
352
365
|
|
|
@@ -362,7 +375,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
362
375
|
});
|
|
363
376
|
newConnection.once('connect', async () => {
|
|
364
377
|
this.connectionsMap[connectionPurpose].creatingConnection = false;
|
|
365
|
-
this.em.emit(
|
|
378
|
+
this.em.emit(connectionCreatedEventName, newConnection);
|
|
366
379
|
isResolved = true;
|
|
367
380
|
resolve(newConnection);
|
|
368
381
|
});
|
|
@@ -698,6 +711,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
698
711
|
}
|
|
699
712
|
|
|
700
713
|
async publish(exchange: string, content: any, customHeaders?: any): Promise<boolean> {
|
|
714
|
+
debug('rabbit: start publish msg');
|
|
701
715
|
return wrapSetImmediate(async () => {
|
|
702
716
|
RabbitMq.validateName('exchange', exchange);
|
|
703
717
|
const channel: ChannelWrapper = await this.assertChannel({ connectionPurpose: ConnectionPurpose.Publish });
|
|
@@ -742,9 +756,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
742
756
|
}
|
|
743
757
|
|
|
744
758
|
async isConnected(): Promise<boolean> {
|
|
759
|
+
debug('rabbit: start is connected');
|
|
745
760
|
const isEachConnectionConnected = await Promise.all(
|
|
746
761
|
Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
747
762
|
const { connection } = connectionData;
|
|
763
|
+
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
748
764
|
if (connectionPurpose === ConnectionPurpose.Publish && !connection) {
|
|
749
765
|
return true; // The connection hasn't been initialized yet, as no messages have been sent through it
|
|
750
766
|
}
|
package/src/lib/consts.ts
CHANGED
|
@@ -6,8 +6,6 @@ export const USER_TRACING_HEADER = 'x-af-user-id';
|
|
|
6
6
|
export const AUTOMATION_ID_HEADER = 'x-af-automation-id';
|
|
7
7
|
export const USER_OBJECT = 'userObject';
|
|
8
8
|
export const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
9
|
-
export const CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
10
|
-
export const CONNECTION_FAILED_CONST = 'connectionFailed';
|
|
11
9
|
export const DEFAULT_OPTIONS = {
|
|
12
10
|
limit: 1,
|
|
13
11
|
retries: 1,
|
package/src/lib/types.ts
CHANGED