@autofleet/rabbit 3.2.26-beta.4 → 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 +12 -18
- package/dist/index.js +107 -200
- 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 +132 -247
- 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,118 +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
293
|
async setupQueue(queueName, options) {
|
|
324
294
|
let queue;
|
|
325
|
-
const connectionPurpose = consts_1.ConnectionPurpose.Publish;
|
|
326
|
-
const shouldUseQuorum = RabbitMq.shouldUseQuorum(queueName);
|
|
327
|
-
const localeOptions = {
|
|
328
|
-
...options,
|
|
329
|
-
durable: true,
|
|
330
|
-
arguments: {
|
|
331
|
-
...options?.arguments,
|
|
332
|
-
'x-consumer-timeout': 1000 * 60 * 60 * 24,
|
|
333
|
-
'x-queue-type': shouldUseQuorum ? 'quorum' : 'classic',
|
|
334
|
-
},
|
|
335
|
-
};
|
|
336
295
|
try {
|
|
337
|
-
const channel = await this.assertChannel(
|
|
296
|
+
const channel = await this.assertChannel();
|
|
338
297
|
debug('assertQueue->channel.addSetup', { queueName });
|
|
339
|
-
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName,
|
|
298
|
+
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
|
|
340
299
|
debug('assertQueue->channel.assertQueue', { queueName });
|
|
341
|
-
queue = await channel.assertQueue(queueName,
|
|
300
|
+
queue = await channel.assertQueue(queueName, options);
|
|
342
301
|
}
|
|
343
302
|
catch (e) {
|
|
344
303
|
logger_1.default.error('rabbit: assertQueue error', { queueName, options, error: e });
|
|
345
304
|
if (!this.options?.dontRetryAssert) {
|
|
346
305
|
debug('retrying assertQueue', { queueName });
|
|
347
|
-
const channel = await this.assertChannel({ force: true
|
|
348
|
-
await this.deleteQueue(queueName
|
|
306
|
+
const channel = await this.assertChannel({ force: true });
|
|
307
|
+
await this.deleteQueue(queueName);
|
|
349
308
|
debug('retrying assertQueue->channel.addSetup', { queueName });
|
|
350
|
-
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName,
|
|
309
|
+
await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
|
|
351
310
|
debug('retrying assertQueue->channel.assertQueue', { queueName });
|
|
352
|
-
queue = await channel.assertQueue(queueName,
|
|
311
|
+
queue = await channel.assertQueue(queueName, options);
|
|
353
312
|
}
|
|
354
313
|
else {
|
|
355
314
|
throw e;
|
|
356
315
|
}
|
|
357
316
|
}
|
|
358
|
-
this.queues[queueName] =
|
|
317
|
+
this.queues[queueName] = queueName;
|
|
359
318
|
return queue;
|
|
360
319
|
}
|
|
361
|
-
static shouldUseQuorum(queueName) {
|
|
362
|
-
const envQuorumQueuesWhitelist = process.env.QUORUM_QUEUES_WHITELIST;
|
|
363
|
-
if (envQuorumQueuesWhitelist === '*') {
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
if (envQuorumQueuesWhitelist) {
|
|
367
|
-
const whitelist = envQuorumQueuesWhitelist.split(',');
|
|
368
|
-
return whitelist.includes(queueName);
|
|
369
|
-
}
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
320
|
async assertQueue(queueName, options) {
|
|
373
|
-
debug('rabbit: start assert queue', { queueName });
|
|
374
321
|
RabbitMq.validateName('queue', queueName);
|
|
375
322
|
if (this.queues[queueName]) {
|
|
376
323
|
delete this.queueSetupPromises[queueName];
|
|
@@ -380,7 +327,6 @@ class RabbitMq {
|
|
|
380
327
|
return this.queueSetupPromises[queueName];
|
|
381
328
|
}
|
|
382
329
|
this.queueSetupPromises[queueName] = this.setupQueue(queueName, options);
|
|
383
|
-
debug('rabbit: done assert queue', { queueName });
|
|
384
330
|
return this.queueSetupPromises[queueName];
|
|
385
331
|
}
|
|
386
332
|
saveConsumer(queue, callback, options) {
|
|
@@ -423,17 +369,16 @@ class RabbitMq {
|
|
|
423
369
|
}
|
|
424
370
|
logger_1.default.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
|
|
425
371
|
}
|
|
426
|
-
const channel = await this.getNewChannel({
|
|
372
|
+
const channel = await this.getNewChannel({ name: `${this.podId}_queue_${queue}` });
|
|
427
373
|
return channel.addSetup(async (confirmChannel) => {
|
|
428
|
-
|
|
429
|
-
await confirmChannel.prefetch(limit,
|
|
374
|
+
await confirmChannel.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
|
|
375
|
+
await confirmChannel.prefetch(limit, true);
|
|
430
376
|
const { consumerTag } = await confirmChannel.consume(queue, async (msg) => {
|
|
431
377
|
if (!msg) {
|
|
432
378
|
return null;
|
|
433
379
|
}
|
|
434
380
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
435
381
|
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
436
|
-
const automationId = msg.properties.headers[consts_1.AUTOMATION_ID_HEADER];
|
|
437
382
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
438
383
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
439
384
|
const trace = (0, zehut_1.newTrace)(zehut_1.traceTypes.RABBIT);
|
|
@@ -458,10 +403,7 @@ class RabbitMq {
|
|
|
458
403
|
outbreakTrace?.context.set(consts_1.TRACING_HEADER, traceId);
|
|
459
404
|
}
|
|
460
405
|
if (auditContext) {
|
|
461
|
-
await auditContext(queue
|
|
462
|
-
userId,
|
|
463
|
-
automationId,
|
|
464
|
-
});
|
|
406
|
+
await auditContext(queue);
|
|
465
407
|
}
|
|
466
408
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
467
409
|
if (!shouldConsume) {
|
|
@@ -507,12 +449,12 @@ class RabbitMq {
|
|
|
507
449
|
RabbitMq.validateName('queue', queue);
|
|
508
450
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
509
451
|
await this.saveConsumer(queue, callback, options);
|
|
510
|
-
const channel = await this.getNewChannel({ name:
|
|
452
|
+
const channel = await this.getNewChannel({ name: `${this.podId}_exchange_${exchange}_queue_${queue}` });
|
|
511
453
|
return channel.addSetup(async (c) => {
|
|
512
454
|
const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
|
|
513
455
|
await c.assertQueue(queue);
|
|
514
456
|
this.exchanges[exchange] = assertExchange;
|
|
515
|
-
await c.prefetch(limit,
|
|
457
|
+
await c.prefetch(limit, true);
|
|
516
458
|
return Promise.all([
|
|
517
459
|
c.bindQueue(queue, exchange, ''),
|
|
518
460
|
this.consume(queue, callback, options),
|
|
@@ -520,86 +462,53 @@ class RabbitMq {
|
|
|
520
462
|
});
|
|
521
463
|
}
|
|
522
464
|
async publish(exchange, content, customHeaders) {
|
|
523
|
-
debug('rabbit: start publish msg');
|
|
524
465
|
return (0, utils_1.wrapSetImmediate)(async () => {
|
|
525
466
|
RabbitMq.validateName('exchange', exchange);
|
|
526
|
-
const channel = await this.assertChannel(
|
|
527
|
-
await this.assertExchange(exchange
|
|
467
|
+
const channel = await this.assertChannel();
|
|
468
|
+
await this.assertExchange(exchange);
|
|
528
469
|
await channel.publish(exchange, '', Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
529
470
|
});
|
|
530
471
|
}
|
|
531
|
-
async sendToQueue(queue, content, options, customHeaders) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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();
|
|
542
489
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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;
|
|
546
498
|
}
|
|
499
|
+
const channel = await this.assertChannel();
|
|
547
500
|
try {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
501
|
+
await Promise.all([
|
|
502
|
+
channel.waitForConnect(),
|
|
503
|
+
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
504
|
+
]);
|
|
551
505
|
}
|
|
552
506
|
catch (e) {
|
|
553
|
-
logger_1.default.error(
|
|
554
|
-
|
|
507
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
508
|
+
return false;
|
|
555
509
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// const isConnected = connection.isConnected();
|
|
559
|
-
// if (!isConnected) {
|
|
560
|
-
// logger.error('rabbit: isConnected - false');
|
|
561
|
-
// return false;
|
|
562
|
-
// }
|
|
563
|
-
// const channel: any = await this.assertChannel();
|
|
564
|
-
// try {
|
|
565
|
-
// await Promise.all([
|
|
566
|
-
// channel.waitForConnect(),
|
|
567
|
-
// ...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
568
|
-
// ]);
|
|
569
|
-
// } catch (e) {
|
|
570
|
-
// logger.error('rabbit: isConnected - false');
|
|
571
|
-
// return false;
|
|
572
|
-
// }
|
|
573
|
-
// logger.info('rabbit: isConnected - true');
|
|
574
|
-
// return true;
|
|
575
|
-
async isConnected() {
|
|
576
|
-
debug('rabbit: start is connected');
|
|
577
|
-
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
578
|
-
const { connection } = connectionData;
|
|
579
|
-
if (connectionPurpose === consts_1.ConnectionPurpose.Publish && connection) {
|
|
580
|
-
const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
|
|
581
|
-
try {
|
|
582
|
-
await Promise.all([
|
|
583
|
-
channel.waitForConnect(),
|
|
584
|
-
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
585
|
-
]);
|
|
586
|
-
}
|
|
587
|
-
catch (e) {
|
|
588
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
if (connection) {
|
|
593
|
-
const isConnected = connection?.isConnected();
|
|
594
|
-
if (!isConnected) {
|
|
595
|
-
logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
logger_1.default.info('rabbit: isConnected - true', { connectionPurpose });
|
|
599
|
-
}
|
|
600
|
-
return true;
|
|
601
|
-
}));
|
|
602
|
-
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
510
|
+
logger_1.default.info('rabbit: isConnected - true');
|
|
511
|
+
return true;
|
|
603
512
|
}
|
|
604
513
|
async gracefulShutdown(signal) {
|
|
605
514
|
const tagsNumber = this.consumersTags.length;
|
|
@@ -618,5 +527,3 @@ class RabbitMq {
|
|
|
618
527
|
}
|
|
619
528
|
}
|
|
620
529
|
exports.default = RabbitMq;
|
|
621
|
-
var celery_1 = require("./lib/celery");
|
|
622
|
-
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",
|