@autofleet/rabbit 3.2.0 → 3.2.2-2.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/.nvmrc CHANGED
@@ -1 +1 @@
1
- v16
1
+ v20
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
3
+ import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from 'amqp-connection-manager';
4
4
  import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
5
5
  import { RedisConfig } from './lib/redis';
6
- import { TRACING_HEADER, USER_TRACING_HEADER } from './lib/consts';
7
- import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache } from './lib/types';
6
+ import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache, QueueSetupPromisesDictionary, ConnectionPurpose, ConnectionData } from './lib/types';
8
7
  export interface IAfRabbitMq {
9
8
  ack: any;
10
9
  nack: any;
@@ -17,6 +16,9 @@ export interface IAfRabbitMq {
17
16
  sendToQueue: any;
18
17
  redisClient?: any;
19
18
  }
19
+ interface NackOptions {
20
+ skipRetry?: boolean;
21
+ }
20
22
  export interface AfRabbitOptions {
21
23
  disableReconnect?: boolean;
22
24
  /**
@@ -31,13 +33,16 @@ export interface AfRabbitOptions {
31
33
  dontRetryAssert?: boolean;
32
34
  rabbitHost?: string;
33
35
  }
34
- declare type newChannelOpts = {
36
+ type newChannelOpts = {
35
37
  name?: string;
36
38
  onClose?: null | ((args: any | null) => void);
39
+ options?: CreateChannelOpts | undefined;
40
+ connectionPurpose: ConnectionPurpose;
37
41
  };
38
- declare type assertChannelOpts = {
42
+ type assertChannelOpts = {
39
43
  channelName?: string;
40
44
  force?: boolean;
45
+ connectionPurpose: ConnectionPurpose;
41
46
  };
42
47
  declare class RabbitMq implements IAfRabbitMq {
43
48
  static parseMsg(msg: any): any;
@@ -55,43 +60,44 @@ declare class RabbitMq implements IAfRabbitMq {
55
60
  DISCONNECT_MSG: string;
56
61
  RECONNECT_MSG: string;
57
62
  channel: ChannelWrapper | null;
63
+ publishChannelSetupPromise: Promise<ChannelWrapper> | null;
58
64
  blockReconnect: boolean | null | undefined;
59
- connection: AmqpConnectionManager | null | undefined;
65
+ connectionsMap: {
66
+ [ConnectionPurpose.Consume]: ConnectionData;
67
+ [ConnectionPurpose.Publish]: ConnectionData;
68
+ };
60
69
  em: EventEmitter;
61
- creatingConnection: boolean;
62
70
  exchanges: ExchangesCache;
63
71
  queues: QueuesCache;
72
+ queueSetupPromises: QueueSetupPromisesDictionary;
64
73
  options: AfRabbitOptions | undefined;
65
74
  redisClient: any;
66
75
  redisLock?: RedisLockType;
67
- userName: string;
68
- password: string;
69
- host: string;
70
76
  /** Array of consumers tags used for canceling consumption */
71
77
  consumersTags: Array<[ConfirmChannel, string]>;
72
78
  private consumers;
73
79
  constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig);
74
80
  private shouldConsumeMessageByTimestamp;
75
- ack: (channel: ChannelWrapper, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: null) => (userMsg: ConsumeMessage) => Promise<any>;
76
- nack: (channel: ChannelWrapper, queue: string, options: any, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock: any) => (userMsg: ConsumeMessageOrNull, { skipRetry, }?: any) => Promise<any>;
77
- getConnection(): Promise<AmqpConnectionManager>;
78
- getNewChannel({ name, onClose }?: newChannelOpts): Promise<ChannelWrapper>;
79
- assertChannel({ force }?: assertChannelOpts): Promise<ChannelWrapper>;
81
+ ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: null) => (userMsg: ConsumeMessage) => Promise<any>;
82
+ nack: (channel: ConfirmChannel, queue: string, options: any, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock: any) => (userMsg: ConsumeMessageOrNull, { skipRetry, }?: NackOptions) => Promise<any>;
83
+ getConnection(connectionPurpose: ConnectionPurpose): Promise<AmqpConnectionManager | null | undefined>;
84
+ getNewChannel({ name, onClose, options, connectionPurpose, }: newChannelOpts): Promise<ChannelWrapper>;
85
+ assertChannel({ force, connectionPurpose }: assertChannelOpts): Promise<ChannelWrapper>;
80
86
  assertExchange(exchangeName: string, options?: any): Promise<any>;
81
- getQueueLength(queue: string): Promise<Replies.AssertQueue>;
87
+ getQueueLength(queue: string, connectionPurpose?: ConnectionPurpose): Promise<Replies.AssertQueue>;
82
88
  private deleteQueue;
83
- bindQueue(queue: string, exchange: string): Promise<void>;
84
- assertQueue(queueName: string, options?: Options.AssertQueue): Promise<any>;
89
+ bindQueue(queue: string, exchange: string, connectionPurpose: ConnectionPurpose): Promise<void>;
90
+ setupQueue(queueName: string, connectionPurpose: ConnectionPurpose, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
91
+ assertQueue(queueName: string, connectionPurpose: ConnectionPurpose, options?: Options.AssertQueue): Promise<any>;
85
92
  private saveConsumer;
86
- private loadConsumers;
87
93
  consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any>;
88
94
  private lockRedisIfNeeded;
89
95
  private unlockRedisIfNeeded;
90
96
  private consumeFromRabbit;
91
97
  consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any>;
92
98
  publish(exchange: string, content: any, customHeaders?: any): Promise<boolean>;
93
- sendToQueue(queue: string, content: any, options?: any, customHeaders?: any, isBlocking?: boolean): Promise<boolean | undefined>;
94
- isConnected(): Promise<boolean>;
99
+ sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<boolean | undefined>;
100
+ isConnected(connectionPurpose: ConnectionPurpose): Promise<boolean>;
95
101
  gracefulShutdown(signal: string): Promise<void>;
96
102
  }
97
103
  export default RabbitMq;