@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/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.publishChannel = null;
121
- this.publishChannelSetupPromise = null;
122
- this.connectionsMap = {
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(connectionPurpose) {
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(connectionCreatedEventName, resolve);
178
- this.em.once(connectionFailedEventName, reject);
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.connectionsMap[connectionPurpose].creatingConnection = true;
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 newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
179
+ const connection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
195
180
  findServers,
196
181
  });
197
- this.connectionsMap[connectionPurpose].connection = newConnection;
198
- logger_1.default.info(`rabbit: created new connection ${connectionPurpose}`);
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(connectionFailedEventName, err);
188
+ this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
205
189
  }
206
190
  });
207
- newConnection.on('connectFailed', (err) => {
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(connectionFailedEventName, err);
197
+ this.em.emit(consts_1.CONNECTION_FAILED_CONST, err);
214
198
  }
215
199
  });
216
- newConnection.on('disconnect', ({ err }) => {
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
- newConnection.once('connect', async () => {
228
- this.connectionsMap[connectionPurpose].creatingConnection = false;
229
- this.em.emit(connectionCreatedEventName, newConnection);
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(newConnection);
216
+ resolve(connection);
232
217
  });
233
218
  });
234
219
  }
235
- async getNewChannel({ name = (0, utils_1.rand)().toString(), onClose = null, options = {}, connectionPurpose = consts_1.ConnectionPurpose.Consume, }) {
220
+ async getNewChannel({ name = (0, utils_1.rand)().toString(), onClose = null, options = {} } = {}) {
236
221
  let connection;
237
222
  try {
238
- connection = await this.getConnection(connectionPurpose);
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
- if (!connection) {
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, connectionPurpose = consts_1.ConnectionPurpose.Consume }) {
263
- debug('rabbit: start assert channel', { connectionPurpose, publishPromise: this.publishChannelSetupPromise, channel: this.publishChannel });
264
- if (!this.publishChannelSetupPromise || (!this.publishChannel && connectionPurpose === consts_1.ConnectionPurpose.Publish)) {
265
- this.publishChannelSetupPromise = new Promise(async (resolve, reject) => {
266
- if (this.publishChannel && !force) {
267
- return resolve(this.publishChannel);
268
- }
269
- try {
270
- const channel = await this.getNewChannel({ connectionPurpose });
271
- debug('rabbit: new channel got', { connectionPurpose, channel: this.publishChannel });
272
- channel.on('error', (err) => {
273
- logger_1.default.error('rabbit: channel error', { err });
274
- });
275
- if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
276
- this.publishChannel = channel;
277
- }
278
- resolve(channel);
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 = { connectionPurpose: consts_1.ConnectionPurpose.Consume }) {
288
- const channel = await this.assertChannel({ connectionPurpose: options.connectionPurpose });
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
- if (this.assertExchangePromises[exchangeName]) {
294
- return this.assertExchangePromises[exchangeName];
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, connectionPurpose = consts_1.ConnectionPurpose.Consume) {
271
+ async getQueueLength(queue) {
301
272
  RabbitMq.validateName('queue', queue);
302
- const { connection } = this.connectionsMap[connectionPurpose];
303
- const { publishChannel } = this;
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 publishChannel?.checkQueue(queue);
277
+ debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
278
+ return channel?.checkQueue(queue);
309
279
  }
310
- async deleteQueue(queue, connectionPurpose) {
280
+ async deleteQueue(queue) {
311
281
  RabbitMq.validateName('queue', queue);
312
- const channel = await this.assertChannel({ connectionPurpose });
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({ connectionPurpose: consts_1.ConnectionPurpose.Publish });
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, connectionPurpose, options) {
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({ connectionPurpose });
296
+ const channel = await this.assertChannel();
337
297
  debug('assertQueue->channel.addSetup', { queueName });
338
- await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, localeOptions));
298
+ await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
339
299
  debug('assertQueue->channel.assertQueue', { queueName });
340
- queue = await channel.assertQueue(queueName, localeOptions);
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, connectionPurpose });
347
- await this.deleteQueue(queueName, connectionPurpose);
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, localeOptions));
309
+ await channel.addSetup((setupChannel) => setupChannel.assertQueue(queueName, options));
350
310
  debug('retrying assertQueue->channel.assertQueue', { queueName });
351
- queue = await channel.assertQueue(queueName, localeOptions);
311
+ queue = await channel.assertQueue(queueName, options);
352
312
  }
353
313
  else {
354
314
  throw e;
355
315
  }
356
316
  }
357
- this.queues[queueName] = queue;
317
+ this.queues[queueName] = queueName;
358
318
  return queue;
359
319
  }
360
- static shouldUseQuorum(queueName) {
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, connectionPurpose, options);
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({ connectionPurpose: consts_1.ConnectionPurpose.Consume });
372
+ const channel = await this.getNewChannel({ name: `${this.podId}_queue_${queue}` });
426
373
  return channel.addSetup(async (confirmChannel) => {
427
- const q = await this.assertQueue(queue, consts_1.ConnectionPurpose.Consume, optionsWithDefaults);
428
- await confirmChannel.prefetch(limit, false);
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: `consume - exchange - ${exchange} -queue - ${queue}` });
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, false);
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({ connectionPurpose: consts_1.ConnectionPurpose.Publish });
526
- await this.assertExchange(exchange, { connectionPurpose: consts_1.ConnectionPurpose.Publish });
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
- try {
532
- await this.assertChannel({ connectionPurpose: consts_1.ConnectionPurpose.Publish });
533
- }
534
- catch (e) {
535
- logger_1.default.error(`rabbit sendToQueue: failed to send assert channel when sending to queue ${queue}`, { e });
536
- throw e;
537
- }
538
- try {
539
- RabbitMq.validateName('queue', queue);
540
- await this.assertQueue(queue, consts_1.ConnectionPurpose.Publish, options);
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
- catch (e) {
543
- logger_1.default.error(`rabbit sendToQueue: failed to assert queue ${queue}`, { e });
544
- throw e;
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
- const res = await this.publishChannel?.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
548
- debug(`rabbit: sending to queue ${queue}`, { res });
549
- return res;
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(`rabbit sendToQueue: failed to send to queue ${queue}`, { e });
553
- throw e;
507
+ logger_1.default.error('rabbit: isConnected - false');
508
+ return false;
554
509
  }
555
- }
556
- async isConnected() {
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; } });
@@ -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
- }
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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 = {}));
@@ -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
- };
@@ -1,5 +1,5 @@
1
1
  import { ChannelWrapper } from 'amqp-connection-manager';
2
- import { ConfirmChannel, Replies } from 'amqplib';
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.2.26-beta.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": "^3.1.2",
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",