@autofleet/rabbit 3.2.26-beta.0 → 3.2.26-beta.2

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.d.ts CHANGED
@@ -88,7 +88,7 @@ declare class RabbitMq implements IAfRabbitMq {
88
88
  assertExchange(exchangeName: string, options?: any): Promise<any>;
89
89
  getQueueLength(queue: string, connectionPurpose?: ConnectionPurpose): Promise<Replies.AssertQueue>;
90
90
  private deleteQueue;
91
- bindQueue(queue: string, exchange: string, connectionPurpose: ConnectionPurpose): Promise<void>;
91
+ bindQueue(queue: string, exchange: string): Promise<void>;
92
92
  setupQueue(queueName: string, connectionPurpose: ConnectionPurpose, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
93
93
  static shouldUseQuorum(queueName: string): boolean;
94
94
  assertQueue(queueName: string, connectionPurpose: ConnectionPurpose, options?: Options.AssertQueue): Promise<any>;
package/dist/index.js CHANGED
@@ -261,7 +261,7 @@ class RabbitMq {
261
261
  }
262
262
  async assertChannel({ force = false, connectionPurpose = consts_1.ConnectionPurpose.Consume }) {
263
263
  debug('rabbit: start assert channel', { connectionPurpose, publishPromise: this.publishChannelSetupPromise, channel: this.publishChannel });
264
- if (!this.publishChannelSetupPromise) {
264
+ if (!this.publishChannelSetupPromise || (!this.publishChannel && connectionPurpose === consts_1.ConnectionPurpose.Publish)) {
265
265
  this.publishChannelSetupPromise = new Promise(async (resolve, reject) => {
266
266
  if (this.publishChannel && !force) {
267
267
  return resolve(this.publishChannel);
@@ -272,7 +272,9 @@ class RabbitMq {
272
272
  channel.on('error', (err) => {
273
273
  logger_1.default.error('rabbit: channel error', { err });
274
274
  });
275
- this.publishChannel = channel;
275
+ if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
276
+ this.publishChannel = channel;
277
+ }
276
278
  resolve(channel);
277
279
  }
278
280
  catch (e) {
@@ -313,8 +315,8 @@ class RabbitMq {
313
315
  debug('queue deleted', deleteQueueRes);
314
316
  return deleteQueueRes;
315
317
  }
316
- async bindQueue(queue, exchange, connectionPurpose) {
317
- const channel = await this.assertChannel({ connectionPurpose });
318
+ async bindQueue(queue, exchange) {
319
+ const channel = await this.assertChannel({ connectionPurpose: consts_1.ConnectionPurpose.Publish });
318
320
  await channel.addSetup((setupChannel) => setupChannel.bindQueue(queue, exchange, ''));
319
321
  return channel.bindQueue(queue, exchange, '');
320
322
  }
@@ -509,7 +511,7 @@ class RabbitMq {
509
511
  const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
510
512
  await c.assertQueue(queue);
511
513
  this.exchanges[exchange] = assertExchange;
512
- await c.prefetch(limit, true);
514
+ await c.prefetch(limit, false);
513
515
  return Promise.all([
514
516
  c.bindQueue(queue, exchange, ''),
515
517
  this.consume(queue, callback, options),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.26-beta.0",
3
+ "version": "3.2.26-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -18,7 +18,7 @@
18
18
  "dev": "nodemon"
19
19
  },
20
20
  "dependencies": {
21
- "@autofleet/zehut": "^3.0.10",
21
+ "@autofleet/zehut": "^3.1.2",
22
22
  "amqp-connection-manager": "4.1.9",
23
23
  "amqplib": "0.10.3",
24
24
  "bluebird": "^3.7.2",
package/src/index.ts CHANGED
@@ -412,7 +412,7 @@ class RabbitMq implements IAfRabbitMq {
412
412
 
413
413
  async assertChannel({ force = false, connectionPurpose = ConnectionPurpose.Consume }: assertChannelOpts): Promise<ChannelWrapper> {
414
414
  debug('rabbit: start assert channel', { connectionPurpose, publishPromise: this.publishChannelSetupPromise, channel: this.publishChannel });
415
- if (!this.publishChannelSetupPromise) {
415
+ if (!this.publishChannelSetupPromise || (!this.publishChannel && connectionPurpose === ConnectionPurpose.Publish)) {
416
416
  this.publishChannelSetupPromise = new Promise<ChannelWrapper>(async (resolve, reject) => {
417
417
  if (this.publishChannel && !force) {
418
418
  return resolve(this.publishChannel);
@@ -424,7 +424,9 @@ class RabbitMq implements IAfRabbitMq {
424
424
  channel.on('error', (err) => {
425
425
  logger.error('rabbit: channel error', { err });
426
426
  });
427
- this.publishChannel = channel;
427
+ if (connectionPurpose === ConnectionPurpose.Publish) {
428
+ this.publishChannel = channel;
429
+ }
428
430
  resolve(channel);
429
431
  } catch (e) {
430
432
  reject(e);
@@ -470,8 +472,8 @@ class RabbitMq implements IAfRabbitMq {
470
472
  return deleteQueueRes;
471
473
  }
472
474
 
473
- async bindQueue(queue: string, exchange: string, connectionPurpose: ConnectionPurpose) {
474
- const channel: ChannelWrapper = await this.assertChannel({ connectionPurpose });
475
+ async bindQueue(queue: string, exchange: string) {
476
+ const channel: ChannelWrapper = await this.assertChannel({ connectionPurpose: ConnectionPurpose.Publish });
475
477
  await channel.addSetup((setupChannel: ConfirmChannel) => setupChannel.bindQueue(queue, exchange, ''));
476
478
  return channel.bindQueue(queue, exchange, '');
477
479
  }
@@ -698,7 +700,7 @@ class RabbitMq implements IAfRabbitMq {
698
700
  const assertExchange = await assertExchangeFanout(c, exchange);
699
701
  await c.assertQueue(queue);
700
702
  this.exchanges[exchange] = assertExchange;
701
- await c.prefetch(limit, true);
703
+ await c.prefetch(limit, false);
702
704
  return Promise.all([
703
705
  c.bindQueue(queue, exchange, ''),
704
706
  this.consume(