@autofleet/rabbit 3.0.0-alpha → 3.0.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
@@ -143,13 +143,13 @@ class RabbitMq {
143
143
  return resolve();
144
144
  }
145
145
  if (this.connection !== null) {
146
- debug('rabbit: connection already exist');
147
146
  if (this.options?.disableReconnect || this.connection?.isConnected()) {
147
+ debug('rabbit: connection - is connected');
148
148
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
149
149
  // @ts-ignore
150
150
  return resolve(this.connection);
151
151
  }
152
- debug('rabbit: connection already exist - reconnecting');
152
+ debug('rabbit: connection - reconnecting');
153
153
  }
154
154
  if (this.creatingConnection) {
155
155
  debug('rabbit: creating connection emi');
@@ -183,7 +183,7 @@ class RabbitMq {
183
183
  });
184
184
  });
185
185
  }
186
- async getNewChannel({ name = '', onClose = null } = {}) {
186
+ async getNewChannel({ name = utils_1.rand().toString(), onClose = null } = {}) {
187
187
  return new Promise(async (resolve, reject) => {
188
188
  const connection = await this.getConnection();
189
189
  const channel = connection.createChannel({});
@@ -326,7 +326,7 @@ class RabbitMq {
326
326
  }
327
327
  logger_1.default.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
328
328
  }
329
- const channel = await this.getNewChannel({ name: `consume-${queue}` });
329
+ const channel = await this.getNewChannel({ name: `consume-queue-${queue}` });
330
330
  return channel.addSetup(async (c) => {
331
331
  await c.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
332
332
  await c.prefetch(limit, true);
@@ -367,7 +367,7 @@ class RabbitMq {
367
367
  RabbitMq.validateName('exchange', exchange);
368
368
  RabbitMq.validateName('queue', queue);
369
369
  const { limit, deadMessageTtl } = optionsWithDefaults;
370
- const channel = await this.getNewChannel();
370
+ const channel = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
371
371
  return channel.addSetup(async (c) => {
372
372
  const assertExchange = await utils_1.assertExchangeFanout(c, exchange);
373
373
  await c.assertQueue(queue);
@@ -2,3 +2,4 @@ import { ChannelWrapper } from 'amqp-connection-manager';
2
2
  import { ConfirmChannel } from 'amqplib';
3
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
+ export declare const rand: () => number;
package/dist/lib/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapSetImmediate = exports.assertExchangeFanout = void 0;
3
+ exports.rand = exports.wrapSetImmediate = exports.assertExchangeFanout = void 0;
4
4
  exports.assertExchangeFanout = async (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
5
5
  exports.wrapSetImmediate = (callback) => new Promise((resolve, reject) => {
6
6
  setImmediate(async () => {
@@ -13,3 +13,4 @@ exports.wrapSetImmediate = (callback) => new Promise((resolve, reject) => {
13
13
  }
14
14
  });
15
15
  });
16
+ exports.rand = () => Math.floor(Math.random() * 100000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.0.0-alpha",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ import { getCurrentContext, newTrace, traceTypes } from '@autofleet/outbreak';
12
12
  import logger from './logger';
13
13
  import RabbitError from './lib/rabbitError';
14
14
  import getRedisInstance, { RedisConfig } from './lib/redis';
15
- import { assertExchangeFanout, wrapSetImmediate } from './lib/utils';
15
+ import { assertExchangeFanout, rand, wrapSetImmediate } from './lib/utils';
16
16
  import {
17
17
  CONNECTION_CREATED_CONST,
18
18
  DEFAULT_LOCK_TIMEOUT,
@@ -259,13 +259,13 @@ class RabbitMq implements IAfRabbitMq {
259
259
  return resolve();
260
260
  }
261
261
  if (this.connection !== null) {
262
- debug('rabbit: connection already exist');
263
262
  if (this.options?.disableReconnect || this.connection?.isConnected()) {
263
+ debug('rabbit: connection - is connected');
264
264
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
265
265
  // @ts-ignore
266
266
  return resolve(this.connection);
267
267
  }
268
- debug('rabbit: connection already exist - reconnecting');
268
+ debug('rabbit: connection - reconnecting');
269
269
  }
270
270
  if (this.creatingConnection) {
271
271
  debug('rabbit: creating connection emi');
@@ -299,7 +299,7 @@ class RabbitMq implements IAfRabbitMq {
299
299
  });
300
300
  }
301
301
 
302
- async getNewChannel({ name = '', onClose = null }: newChannelOpts = {}) {
302
+ async getNewChannel({ name = rand().toString(), onClose = null }: newChannelOpts = {}) {
303
303
  return new Promise<ChannelWrapper>(async (resolve, reject) => {
304
304
  const connection: AmqpConnectionManager = await this.getConnection();
305
305
  const channel = connection.createChannel({});
@@ -463,7 +463,7 @@ class RabbitMq implements IAfRabbitMq {
463
463
  }
464
464
  logger.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
465
465
  }
466
- const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-${queue}` });
466
+ const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-queue-${queue}` });
467
467
  return channel.addSetup(async (c: ConfirmChannel) => {
468
468
  await c.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
469
469
  await c.prefetch(limit, true);
@@ -512,7 +512,7 @@ class RabbitMq implements IAfRabbitMq {
512
512
  RabbitMq.validateName('exchange', exchange);
513
513
  RabbitMq.validateName('queue', queue);
514
514
  const { limit, deadMessageTtl } = optionsWithDefaults;
515
- const channel: ChannelWrapper = await this.getNewChannel();
515
+ const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-exchange-${exchange}-queue-${queue}` });
516
516
 
517
517
  return channel.addSetup(async (c: ConfirmChannel) => {
518
518
  const assertExchange = await assertExchangeFanout(c, exchange);
package/src/lib/utils.ts CHANGED
@@ -12,3 +12,4 @@ export const wrapSetImmediate = (callback: () => any) => new Promise<any>((resol
12
12
  }
13
13
  });
14
14
  });
15
+ export const rand = () => Math.floor(Math.random() * 100000);