@autofleet/rabbit 3.2.26-beta.3 → 3.3.0-beta.0
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/coverage/clover.xml +7 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +212 -0
- package/coverage/lcov-report/index.html +60 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +1 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +158 -0
- package/coverage/lcov.info +0 -0
- package/dist/index.d.ts +14 -20
- package/dist/index.js +110 -183
- package/dist/lib/consts.d.ts +2 -5
- package/dist/lib/consts.js +3 -7
- package/dist/lib/types.d.ts +0 -10
- package/dist/lib/utils.d.ts +2 -2
- package/package.json +2 -5
- package/src/index.ts +135 -228
- package/src/lib/consts.ts +2 -6
- package/src/lib/types.ts +0 -12
- package/src/lib/utils.ts +2 -6
- package/dist/lib/celery.d.ts +0 -9
- package/dist/lib/celery.js +0 -54
- package/src/lib/celery.ts +0 -89
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.sendCeleryTaskViaHttp = void 0;
|
|
8
7
|
const events_1 = require("events");
|
|
9
8
|
const util_1 = require("util");
|
|
10
9
|
const moment_1 = __importDefault(require("moment"));
|
|
@@ -117,28 +116,15 @@ class RabbitMq {
|
|
|
117
116
|
}
|
|
118
117
|
};
|
|
119
118
|
this.em = new events_1.EventEmitter();
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
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
|
-
},
|
|
135
|
-
};
|
|
119
|
+
this.channel = null;
|
|
120
|
+
this.connection = null;
|
|
121
|
+
this.creatingConnection = false;
|
|
136
122
|
this.exchanges = {};
|
|
137
123
|
this.queues = {};
|
|
138
124
|
this.queueSetupPromises = {};
|
|
139
|
-
this.assertExchangePromises = {};
|
|
140
125
|
this.consumers = [];
|
|
141
126
|
this.options = options;
|
|
127
|
+
this.podId = `${options?.serviceName}${options?.podIp ? `-${options.podIp}` : ''}`;
|
|
142
128
|
this.redisClient = redisConfig && (0, redis_1.default)(redisConfig);
|
|
143
129
|
if (this.redisClient) {
|
|
144
130
|
this.redisLock = (0, util_1.promisify)((0, redis_lock_1.default)(this.redisClient));
|
|
@@ -154,31 +140,30 @@ class RabbitMq {
|
|
|
154
140
|
});
|
|
155
141
|
}
|
|
156
142
|
}
|
|
157
|
-
async getConnection(
|
|
143
|
+
async getConnection() {
|
|
158
144
|
return new Promise(async (resolve, reject) => {
|
|
159
|
-
const { connection, creatingConnection, connectionCreatedEventName, connectionFailedEventName, } = this.connectionsMap[connectionPurpose];
|
|
160
145
|
if (this.blockReconnect) {
|
|
161
146
|
debug('rabbit: block reconnect');
|
|
162
147
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
163
148
|
// @ts-ignore
|
|
164
149
|
return resolve();
|
|
165
150
|
}
|
|
166
|
-
if (connection !== null) {
|
|
167
|
-
if (this.options?.disableReconnect || connection?.isConnected()) {
|
|
151
|
+
if (this.connection !== null) {
|
|
152
|
+
if (this.options?.disableReconnect || this.connection?.isConnected()) {
|
|
168
153
|
debug('rabbit: connection - is connected');
|
|
169
154
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
170
155
|
// @ts-ignore
|
|
171
|
-
return resolve(connection);
|
|
156
|
+
return resolve(this.connection);
|
|
172
157
|
}
|
|
173
158
|
debug('rabbit: connection - reconnecting');
|
|
174
159
|
}
|
|
175
|
-
if (creatingConnection) {
|
|
160
|
+
if (this.creatingConnection) {
|
|
176
161
|
debug('rabbit: creating connection emi');
|
|
177
|
-
this.em.once(
|
|
178
|
-
this.em.once(
|
|
162
|
+
this.em.once(consts_1.CONNECTION_CREATED_CONST, resolve);
|
|
163
|
+
this.em.once(consts_1.CONNECTION_FAILED_CONST, reject);
|
|
179
164
|
return;
|
|
180
165
|
}
|
|
181
|
-
this.
|
|
166
|
+
this.creatingConnection = true;
|
|
182
167
|
let isResolved = false;
|
|
183
168
|
// It is import to use it as a function and not as a variable
|
|
184
169
|
// because of k8s changes the env variables
|
|
@@ -191,29 +176,28 @@ class RabbitMq {
|
|
|
191
176
|
return [`amqp://${userName}:${password}@${host}?heartbeat=${HEARTBEAT}`];
|
|
192
177
|
};
|
|
193
178
|
const defaultUrls = findServers();
|
|
194
|
-
const
|
|
179
|
+
const connection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
|
|
195
180
|
findServers,
|
|
196
181
|
});
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
newConnection.on('error', (err) => {
|
|
182
|
+
this.connection = connection;
|
|
183
|
+
this.connection.on('error', (err) => {
|
|
200
184
|
logger_1.default.error('rabbit: connection error', { err });
|
|
201
185
|
if (!isResolved) {
|
|
202
186
|
isResolved = true;
|
|
203
187
|
reject(err);
|
|
204
|
-
this.em.emit(
|
|
188
|
+
this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
|
|
205
189
|
}
|
|
206
190
|
});
|
|
207
|
-
|
|
191
|
+
this.connection.on('connectFailed', (err) => {
|
|
208
192
|
this.consumersTags = [];
|
|
209
193
|
logger_1.default.error('rabbit: connection connectFailed', { err });
|
|
210
194
|
if (!isResolved) {
|
|
211
195
|
isResolved = true;
|
|
212
196
|
reject(err);
|
|
213
|
-
this.em.emit(
|
|
197
|
+
this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
|
|
214
198
|
}
|
|
215
199
|
});
|
|
216
|
-
|
|
200
|
+
this.connection.on('disconnect', ({ err }) => {
|
|
217
201
|
this.consumersTags = [];
|
|
218
202
|
debug('rabbit: connection closed');
|
|
219
203
|
if (this.options?.disableReconnect) {
|
|
@@ -224,27 +208,25 @@ class RabbitMq {
|
|
|
224
208
|
logger_1.default.error(`${this.RECONNECT_MSG}${err && ` - ${err}`}`);
|
|
225
209
|
}
|
|
226
210
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.
|
|
211
|
+
this.connection.once('connect', async () => {
|
|
212
|
+
debug('rabbit: connection established');
|
|
213
|
+
this.creatingConnection = false;
|
|
214
|
+
this.em.emit(consts_1.CONNECTION_CREATED_CONST, connection);
|
|
230
215
|
isResolved = true;
|
|
231
|
-
resolve(
|
|
216
|
+
resolve(connection);
|
|
232
217
|
});
|
|
233
218
|
});
|
|
234
219
|
}
|
|
235
|
-
async getNewChannel({ name = (0, utils_1.rand)().toString(), onClose = null, options = {}
|
|
220
|
+
async getNewChannel({ name = (0, utils_1.rand)().toString(), onClose = null, options = {} } = {}) {
|
|
236
221
|
let connection;
|
|
237
222
|
try {
|
|
238
|
-
connection = await this.getConnection(
|
|
223
|
+
connection = await this.getConnection();
|
|
239
224
|
}
|
|
240
225
|
catch (e) {
|
|
241
226
|
logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
242
227
|
throw e;
|
|
243
228
|
}
|
|
244
|
-
|
|
245
|
-
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
246
|
-
}
|
|
247
|
-
const channel = connection.createChannel({ ...options });
|
|
229
|
+
const channel = connection.createChannel({ ...options, name });
|
|
248
230
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
249
231
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
|
250
232
|
onClose?.(args);
|
|
@@ -259,117 +241,83 @@ class RabbitMq {
|
|
|
259
241
|
throw err;
|
|
260
242
|
}
|
|
261
243
|
}
|
|
262
|
-
async assertChannel({ force = false
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
reject(e);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return this.publishChannelSetupPromise;
|
|
244
|
+
async assertChannel({ force = false } = {}) {
|
|
245
|
+
return new Promise(async (resolve, reject) => {
|
|
246
|
+
if (this.channel && !force) {
|
|
247
|
+
return resolve(this.channel);
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const channel = await this.getNewChannel({});
|
|
251
|
+
channel.on('error', (err) => {
|
|
252
|
+
logger_1.default.error('rabbit: channel error', { err });
|
|
253
|
+
});
|
|
254
|
+
this.channel = channel;
|
|
255
|
+
resolve(channel);
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
reject(e);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
286
261
|
}
|
|
287
|
-
async assertExchange(exchangeName, options
|
|
288
|
-
const channel = await this.assertChannel(
|
|
262
|
+
async assertExchange(exchangeName, options) {
|
|
263
|
+
const channel = await this.assertChannel();
|
|
289
264
|
if (this.exchanges[exchangeName]) {
|
|
290
|
-
delete this.assertExchangePromises[exchangeName];
|
|
291
265
|
return this.exchanges[exchangeName];
|
|
292
266
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.assertExchangePromises[exchangeName] = (0, utils_1.assertExchangeFanout)(channel, exchangeName);
|
|
297
|
-
this.exchanges[exchangeName] = await this.assertExchangePromises[exchangeName];
|
|
298
|
-
return this.exchanges[exchangeName];
|
|
267
|
+
const exchange = await (0, utils_1.assertExchangeFanout)(channel, exchangeName);
|
|
268
|
+
this.exchanges[exchangeName] = exchange;
|
|
269
|
+
return exchange;
|
|
299
270
|
}
|
|
300
|
-
async getQueueLength(queue
|
|
271
|
+
async getQueueLength(queue) {
|
|
301
272
|
RabbitMq.validateName('queue', queue);
|
|
302
|
-
const {
|
|
303
|
-
|
|
304
|
-
if (!publishChannel) {
|
|
273
|
+
const { channel } = this;
|
|
274
|
+
if (!channel) {
|
|
305
275
|
throw new Error('channel is not defined');
|
|
306
276
|
}
|
|
307
|
-
debug('rabbit: getting queue length', { queue, connected: connection?.isConnected() });
|
|
308
|
-
return
|
|
277
|
+
debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
|
|
278
|
+
return channel?.checkQueue(queue);
|
|
309
279
|
}
|
|
310
|
-
async deleteQueue(queue
|
|
280
|
+
async deleteQueue(queue) {
|
|
311
281
|
RabbitMq.validateName('queue', queue);
|
|
312
|
-
const channel = await this.assertChannel(
|
|
282
|
+
const channel = await this.assertChannel();
|
|
313
283
|
logger_1.default.info('rabbit: deleting queue', { queue });
|
|
314
284
|
const deleteQueueRes = await channel.deleteQueue(queue);
|
|
315
285
|
debug('queue deleted', deleteQueueRes);
|
|
316
286
|
return deleteQueueRes;
|
|
317
287
|
}
|
|
318
288
|
async bindQueue(queue, exchange) {
|
|
319
|
-
const channel = await this.assertChannel(
|
|
289
|
+
const channel = await this.assertChannel();
|
|
320
290
|
await channel.addSetup((setupChannel) => setupChannel.bindQueue(queue, exchange, ''));
|
|
321
291
|
return channel.bindQueue(queue, exchange, '');
|
|
322
292
|
}
|
|
323
|
-
async setupQueue(queueName,
|
|
293
|
+
async setupQueue(queueName, options) {
|
|
324
294
|
let queue;
|
|
325
|
-
const shouldUseQuorum = RabbitMq.shouldUseQuorum(queueName);
|
|
326
|
-
const localeOptions = {
|
|
327
|
-
...options,
|
|
328
|
-
durable: true,
|
|
329
|
-
arguments: {
|
|
330
|
-
...options?.arguments,
|
|
331
|
-
'x-consumer-timeout': 1000 * 60 * 60 * 24,
|
|
332
|
-
'x-queue-type': shouldUseQuorum ? 'quorum' : 'classic',
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
295
|
try {
|
|
336
|
-
const channel = await this.assertChannel(
|
|
296
|
+
const channel = await this.assertChannel();
|
|
337
297
|
debug('assertQueue->channel.addSetup', { queueName });
|
|
338
|
-
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName,
|
|
298
|
+
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
|
|
339
299
|
debug('assertQueue->channel.assertQueue', { queueName });
|
|
340
|
-
queue = await channel.assertQueue(queueName,
|
|
300
|
+
queue = await channel.assertQueue(queueName, options);
|
|
341
301
|
}
|
|
342
302
|
catch (e) {
|
|
343
303
|
logger_1.default.error('rabbit: assertQueue error', { queueName, options, error: e });
|
|
344
304
|
if (!this.options?.dontRetryAssert) {
|
|
345
305
|
debug('retrying assertQueue', { queueName });
|
|
346
|
-
const channel = await this.assertChannel({ force: true
|
|
347
|
-
await this.deleteQueue(queueName
|
|
306
|
+
const channel = await this.assertChannel({ force: true });
|
|
307
|
+
await this.deleteQueue(queueName);
|
|
348
308
|
debug('retrying assertQueue->channel.addSetup', { queueName });
|
|
349
|
-
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName,
|
|
309
|
+
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
|
|
350
310
|
debug('retrying assertQueue->channel.assertQueue', { queueName });
|
|
351
|
-
queue = await channel.assertQueue(queueName,
|
|
311
|
+
queue = await channel.assertQueue(queueName, options);
|
|
352
312
|
}
|
|
353
313
|
else {
|
|
354
314
|
throw e;
|
|
355
315
|
}
|
|
356
316
|
}
|
|
357
|
-
this.queues[queueName] =
|
|
317
|
+
this.queues[queueName] = queueName;
|
|
358
318
|
return queue;
|
|
359
319
|
}
|
|
360
|
-
|
|
361
|
-
const envQuorumQueuesWhitelist = process.env.QUORUM_QUEUES_WHITELIST;
|
|
362
|
-
if (envQuorumQueuesWhitelist === '*') {
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
if (envQuorumQueuesWhitelist) {
|
|
366
|
-
const whitelist = envQuorumQueuesWhitelist.split(',');
|
|
367
|
-
return whitelist.includes(queueName);
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
370
|
-
}
|
|
371
|
-
async assertQueue(queueName, connectionPurpose, options) {
|
|
372
|
-
debug('rabbit: start assert queue', { connectionPurpose, queueName });
|
|
320
|
+
async assertQueue(queueName, options) {
|
|
373
321
|
RabbitMq.validateName('queue', queueName);
|
|
374
322
|
if (this.queues[queueName]) {
|
|
375
323
|
delete this.queueSetupPromises[queueName];
|
|
@@ -378,8 +326,7 @@ class RabbitMq {
|
|
|
378
326
|
if (this.queueSetupPromises[queueName]) {
|
|
379
327
|
return this.queueSetupPromises[queueName];
|
|
380
328
|
}
|
|
381
|
-
this.queueSetupPromises[queueName] = this.setupQueue(queueName,
|
|
382
|
-
debug('rabbit: done assert queue', { connectionPurpose, queueName });
|
|
329
|
+
this.queueSetupPromises[queueName] = this.setupQueue(queueName, options);
|
|
383
330
|
return this.queueSetupPromises[queueName];
|
|
384
331
|
}
|
|
385
332
|
saveConsumer(queue, callback, options) {
|
|
@@ -422,17 +369,16 @@ class RabbitMq {
|
|
|
422
369
|
}
|
|
423
370
|
logger_1.default.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
|
|
424
371
|
}
|
|
425
|
-
const channel = await this.getNewChannel({
|
|
372
|
+
const channel = await this.getNewChannel({ name: `${this.podId}_queue_${queue}` });
|
|
426
373
|
return channel.addSetup(async (confirmChannel) => {
|
|
427
|
-
|
|
428
|
-
await confirmChannel.prefetch(limit,
|
|
374
|
+
await confirmChannel.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
|
|
375
|
+
await confirmChannel.prefetch(limit, true);
|
|
429
376
|
const { consumerTag } = await confirmChannel.consume(queue, async (msg) => {
|
|
430
377
|
if (!msg) {
|
|
431
378
|
return null;
|
|
432
379
|
}
|
|
433
380
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
434
381
|
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
435
|
-
const automationId = msg.properties.headers[consts_1.AUTOMATION_ID_HEADER];
|
|
436
382
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
437
383
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
438
384
|
const trace = (0, zehut_1.newTrace)(zehut_1.traceTypes.RABBIT);
|
|
@@ -457,10 +403,7 @@ class RabbitMq {
|
|
|
457
403
|
outbreakTrace?.context.set(consts_1.TRACING_HEADER, traceId);
|
|
458
404
|
}
|
|
459
405
|
if (auditContext) {
|
|
460
|
-
await auditContext(queue
|
|
461
|
-
userId,
|
|
462
|
-
automationId,
|
|
463
|
-
});
|
|
406
|
+
await auditContext(queue);
|
|
464
407
|
}
|
|
465
408
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
466
409
|
if (!shouldConsume) {
|
|
@@ -506,12 +449,12 @@ class RabbitMq {
|
|
|
506
449
|
RabbitMq.validateName('queue', queue);
|
|
507
450
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
508
451
|
await this.saveConsumer(queue, callback, options);
|
|
509
|
-
const channel = await this.getNewChannel({ name:
|
|
452
|
+
const channel = await this.getNewChannel({ name: `${this.podId}_exchange_${exchange}_queue_${queue}` });
|
|
510
453
|
return channel.addSetup(async (c) => {
|
|
511
454
|
const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
|
|
512
455
|
await c.assertQueue(queue);
|
|
513
456
|
this.exchanges[exchange] = assertExchange;
|
|
514
|
-
await c.prefetch(limit,
|
|
457
|
+
await c.prefetch(limit, true);
|
|
515
458
|
return Promise.all([
|
|
516
459
|
c.bindQueue(queue, exchange, ''),
|
|
517
460
|
this.consume(queue, callback, options),
|
|
@@ -519,67 +462,53 @@ class RabbitMq {
|
|
|
519
462
|
});
|
|
520
463
|
}
|
|
521
464
|
async publish(exchange, content, customHeaders) {
|
|
522
|
-
debug('rabbit: start publish msg');
|
|
523
465
|
return (0, utils_1.wrapSetImmediate)(async () => {
|
|
524
466
|
RabbitMq.validateName('exchange', exchange);
|
|
525
|
-
const channel = await this.assertChannel(
|
|
526
|
-
await this.assertExchange(exchange
|
|
467
|
+
const channel = await this.assertChannel();
|
|
468
|
+
await this.assertExchange(exchange);
|
|
527
469
|
await channel.publish(exchange, '', Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
528
470
|
});
|
|
529
471
|
}
|
|
530
|
-
async sendToQueue(queue, content, options, customHeaders) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
472
|
+
async sendToQueue(queue, content, options, customHeaders, isBlocking) {
|
|
473
|
+
const callback = async () => {
|
|
474
|
+
try {
|
|
475
|
+
RabbitMq.validateName('queue', queue);
|
|
476
|
+
await this.assertChannel();
|
|
477
|
+
await this.assertQueue(queue, options);
|
|
478
|
+
const res = await this.channel?.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
479
|
+
debug(`rabbit: sending to queue ${queue}`, { res });
|
|
480
|
+
return res;
|
|
481
|
+
}
|
|
482
|
+
catch (e) {
|
|
483
|
+
logger_1.default.error(`rabbit: failed to send to queue ${queue}`, { e });
|
|
484
|
+
throw e;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
if (isBlocking) {
|
|
488
|
+
return callback();
|
|
541
489
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
490
|
+
return (0, utils_1.wrapSetImmediate)(callback);
|
|
491
|
+
}
|
|
492
|
+
async isConnected() {
|
|
493
|
+
const connection = await this.getConnection();
|
|
494
|
+
const isConnected = connection.isConnected();
|
|
495
|
+
if (!isConnected) {
|
|
496
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
497
|
+
return false;
|
|
545
498
|
}
|
|
499
|
+
const channel = await this.assertChannel();
|
|
546
500
|
try {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
501
|
+
await Promise.all([
|
|
502
|
+
channel.waitForConnect(),
|
|
503
|
+
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
504
|
+
]);
|
|
550
505
|
}
|
|
551
506
|
catch (e) {
|
|
552
|
-
logger_1.default.error(
|
|
553
|
-
|
|
507
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
508
|
+
return false;
|
|
554
509
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
debug('rabbit: start is connected');
|
|
558
|
-
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
559
|
-
if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
|
|
560
|
-
const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
|
|
561
|
-
try {
|
|
562
|
-
await Promise.all([
|
|
563
|
-
channel.waitForConnect(),
|
|
564
|
-
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
565
|
-
]);
|
|
566
|
-
}
|
|
567
|
-
catch (e) {
|
|
568
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
569
|
-
return false;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
const { connection } = connectionData;
|
|
573
|
-
debug('rabbit: is connected inside map', { connection, connectionPurpose });
|
|
574
|
-
const isConnected = connection?.isConnected();
|
|
575
|
-
if (!isConnected) {
|
|
576
|
-
logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
logger_1.default.info('rabbit: isConnected - true');
|
|
580
|
-
return true;
|
|
581
|
-
}));
|
|
582
|
-
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
510
|
+
logger_1.default.info('rabbit: isConnected - true');
|
|
511
|
+
return true;
|
|
583
512
|
}
|
|
584
513
|
async gracefulShutdown(signal) {
|
|
585
514
|
const tagsNumber = this.consumersTags.length;
|
|
@@ -598,5 +527,3 @@ class RabbitMq {
|
|
|
598
527
|
}
|
|
599
528
|
}
|
|
600
529
|
exports.default = RabbitMq;
|
|
601
|
-
var celery_1 = require("./lib/celery");
|
|
602
|
-
Object.defineProperty(exports, "sendCeleryTaskViaHttp", { enumerable: true, get: function () { return celery_1.sendCeleryTaskViaHttp; } });
|
package/dist/lib/consts.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ export declare const DEFAULT_LOCK_TIMEOUT: number;
|
|
|
3
3
|
export declare const RETRY_HEADER = "x-retry-count";
|
|
4
4
|
export declare const TRACING_HEADER = "x-trace-id";
|
|
5
5
|
export declare const USER_TRACING_HEADER = "x-af-user-id";
|
|
6
|
-
export declare const AUTOMATION_ID_HEADER = "x-af-automation-id";
|
|
7
6
|
export declare const USER_OBJECT = "userObject";
|
|
8
7
|
export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
8
|
+
export declare const CONNECTION_CREATED_CONST = "connectionCreated";
|
|
9
|
+
export declare const CONNECTION_FAILED_CONST = "connectionFailed";
|
|
9
10
|
export declare const DEFAULT_OPTIONS: {
|
|
10
11
|
limit: number;
|
|
11
12
|
retries: number;
|
|
@@ -15,7 +16,3 @@ export declare const DEFAULT_OPTIONS: {
|
|
|
15
16
|
auditContext: null;
|
|
16
17
|
enableRabbitTrace: boolean;
|
|
17
18
|
};
|
|
18
|
-
export declare enum ConnectionPurpose {
|
|
19
|
-
Consume = "consume",
|
|
20
|
-
Publish = "publish"
|
|
21
|
-
}
|
package/dist/lib/consts.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DEFAULT_OPTIONS = exports.CONNECTION_FAILED_CONST = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = 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';
|
|
7
7
|
exports.TRACING_HEADER = 'x-trace-id';
|
|
8
8
|
exports.USER_TRACING_HEADER = 'x-af-user-id';
|
|
9
|
-
exports.AUTOMATION_ID_HEADER = 'x-af-automation-id';
|
|
10
9
|
exports.USER_OBJECT = 'userObject';
|
|
11
10
|
exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
11
|
+
exports.CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
12
|
+
exports.CONNECTION_FAILED_CONST = 'connectionFailed';
|
|
12
13
|
exports.DEFAULT_OPTIONS = {
|
|
13
14
|
limit: 1,
|
|
14
15
|
retries: 1,
|
|
@@ -18,8 +19,3 @@ exports.DEFAULT_OPTIONS = {
|
|
|
18
19
|
auditContext: null,
|
|
19
20
|
enableRabbitTrace: false,
|
|
20
21
|
};
|
|
21
|
-
var ConnectionPurpose;
|
|
22
|
-
(function (ConnectionPurpose) {
|
|
23
|
-
ConnectionPurpose["Consume"] = "consume";
|
|
24
|
-
ConnectionPurpose["Publish"] = "publish";
|
|
25
|
-
})(ConnectionPurpose = exports.ConnectionPurpose || (exports.ConnectionPurpose = {}));
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AmqpConnectionManager } from 'amqp-connection-manager';
|
|
2
1
|
import { ConsumeMessage, Options, Replies } from 'amqplib';
|
|
3
2
|
export interface ExchangesCache {
|
|
4
3
|
[key: string]: any;
|
|
@@ -9,9 +8,6 @@ export interface QueuesCache {
|
|
|
9
8
|
export interface QueueSetupPromisesDictionary {
|
|
10
9
|
[key: string]: Promise<Replies.AssertQueue> | undefined;
|
|
11
10
|
}
|
|
12
|
-
export interface AssertExchangePromisesDictionary {
|
|
13
|
-
[key: string]: Promise<Replies.AssertExchange> | undefined;
|
|
14
|
-
}
|
|
15
11
|
export type CustomMessageHeaders = {
|
|
16
12
|
redisTimestampValidationKey?: string;
|
|
17
13
|
};
|
|
@@ -42,9 +38,3 @@ export type AfConsumer = {
|
|
|
42
38
|
options: ConsumeOptions | undefined;
|
|
43
39
|
};
|
|
44
40
|
export declare const CONSUMER_DEFAULT_OPTIONS: Options.Consume;
|
|
45
|
-
export type ConnectionData = {
|
|
46
|
-
connection: AmqpConnectionManager | null;
|
|
47
|
-
creatingConnection: boolean;
|
|
48
|
-
connectionCreatedEventName: string;
|
|
49
|
-
connectionFailedEventName: string;
|
|
50
|
-
};
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChannelWrapper } from 'amqp-connection-manager';
|
|
2
|
-
import { ConfirmChannel
|
|
3
|
-
export declare const assertExchangeFanout: (c: ChannelWrapper | ConfirmChannel, exchangeName: string) => Promise<Replies.AssertExchange>;
|
|
2
|
+
import { ConfirmChannel } from 'amqplib';
|
|
3
|
+
export declare const assertExchangeFanout: (c: ChannelWrapper | ConfirmChannel, exchangeName: string) => Promise<import("amqplib").Replies.AssertExchange>;
|
|
4
4
|
export declare const wrapSetImmediate: (callback: () => any) => Promise<any>;
|
|
5
5
|
export declare const rand: () => number;
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=16.7.0"
|
|
8
|
-
},
|
|
9
6
|
"scripts": {
|
|
10
7
|
"postinstall": "echo '\\033[0;31m\nWARNING: in case of migrating to new version of @autofleet/rabbit \nyou might have to delete existing queues or the deployment will fail.\\033[0m\n'",
|
|
11
8
|
"start": "ts-node src/index.ts",
|
|
@@ -18,7 +15,7 @@
|
|
|
18
15
|
"dev": "nodemon"
|
|
19
16
|
},
|
|
20
17
|
"dependencies": {
|
|
21
|
-
"@autofleet/zehut": "
|
|
18
|
+
"@autofleet/zehut": "3.0.8",
|
|
22
19
|
"amqp-connection-manager": "4.1.9",
|
|
23
20
|
"amqplib": "0.10.3",
|
|
24
21
|
"bluebird": "^3.7.2",
|