@autofleet/rabbit 4.0.2 → 4.1.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.d.ts +63 -72
- package/dist/index.js +378 -393
- package/dist/index.js.map +1 -1
- package/dist/lib/consts.d.ts +2 -2
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/redis.d.ts +2 -1
- package/dist/lib/redis.js +2 -8
- package/dist/lib/redis.js.map +1 -1
- package/dist/lib/types.d.ts +11 -6
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.d.ts +12 -8
- package/dist/lib/utils.js +15 -13
- package/dist/lib/utils.js.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +475 -538
- package/src/lib/consts.ts +8 -4
- package/src/lib/redis.ts +2 -7
- package/src/lib/types.ts +13 -8
- package/src/lib/utils.ts +27 -14
- package/src/redis-lock.d.ts +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import RedisLock from 'redis-lock';
|
|
4
|
+
import { type AmqpConnectionManager, type ChannelWrapper, type CreateChannelOpts } from 'amqp-connection-manager';
|
|
5
|
+
import type { PublishOptions } from 'amqp-connection-manager/dist/types/ChannelWrapper';
|
|
4
6
|
import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
+
import type { LoggerInstanceManager } from '@autofleet/logger';
|
|
8
|
+
import getRedisInstance, { RedisConfig } from './lib/redis';
|
|
9
|
+
import { type AssertExchangePromisesDictionary, type CallbackFunction, type ConnectionData, type ConsumeMessageOrNull, type ConsumeOptions, type CustomMessageHeaders, type ExchangesCache, type Message, type NackOptions, type QueuesCache, type QueueSetupPromisesDictionary } from './lib/types';
|
|
7
10
|
export interface IAfRabbitMq {
|
|
8
|
-
ack:
|
|
9
|
-
nack:
|
|
10
|
-
assertChannel:
|
|
11
|
-
assertExchange:
|
|
12
|
-
assertQueue:
|
|
13
|
-
consume:
|
|
14
|
-
consumeFromExchange:
|
|
15
|
-
publish: any
|
|
16
|
-
sendToQueue: any
|
|
17
|
-
redisClient?:
|
|
18
|
-
}
|
|
19
|
-
interface NackOptions {
|
|
20
|
-
skipRetry?: boolean;
|
|
11
|
+
ack(channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null): (userMsg: ConsumeMessage) => Promise<void>;
|
|
12
|
+
nack(channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: () => Promise<void>): (userMsg: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>;
|
|
13
|
+
assertChannel(options?: assertChannelOpts): Promise<ChannelWrapper>;
|
|
14
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
15
|
+
assertQueue(queueName: string, options?: Options.AssertQueue | null): Promise<Replies.AssertQueue>;
|
|
16
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
17
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
18
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions['headers']): Promise<void>;
|
|
19
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue | null, customHeaders?: PublishOptions['headers']): Promise<boolean | undefined>;
|
|
20
|
+
redisClient?: ReturnType<typeof getRedisInstance>;
|
|
21
21
|
}
|
|
22
22
|
export interface AfRabbitOptions {
|
|
23
23
|
disableReconnect?: boolean;
|
|
@@ -27,12 +27,13 @@ export interface AfRabbitOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
dontGracefulShutdown?: boolean;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* don't retry on creation error
|
|
31
31
|
* @default false
|
|
32
32
|
*/
|
|
33
33
|
dontRetryAssert?: boolean;
|
|
34
34
|
rabbitHost?: string;
|
|
35
35
|
vhost?: string;
|
|
36
|
+
logger?: LoggerInstanceManager;
|
|
36
37
|
}
|
|
37
38
|
type newChannelOpts = {
|
|
38
39
|
name?: string;
|
|
@@ -46,95 +47,85 @@ type assertChannelOpts = {
|
|
|
46
47
|
connection: ConnectionData;
|
|
47
48
|
};
|
|
48
49
|
declare class RabbitMq implements IAfRabbitMq {
|
|
49
|
-
|
|
50
|
+
#private;
|
|
51
|
+
readonly options: AfRabbitOptions;
|
|
52
|
+
private readonly redisConfig?;
|
|
53
|
+
static parseMsg(msg: ConsumeMessage): Message;
|
|
50
54
|
static validateName(type: string, name: string): void;
|
|
51
|
-
static getPublishOptions(customHeaders?: CustomMessageHeaders):
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
headers: {
|
|
55
|
-
"x-af-user-id": any;
|
|
56
|
-
"x-trace-id": any;
|
|
57
|
-
redisTimestampValidationKey?: string | undefined;
|
|
58
|
-
creationTimestamp: number;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
DISCONNECT_MSG: string;
|
|
62
|
-
RECONNECT_MSG: string;
|
|
55
|
+
static getPublishOptions(customHeaders?: CustomMessageHeaders): PublishOptions;
|
|
56
|
+
readonly DISCONNECT_MSG = "rabbit: connection disconnect";
|
|
57
|
+
readonly RECONNECT_MSG = "rabbit: connection disconnect - reconnecting";
|
|
63
58
|
publishChannel: ChannelWrapper | null;
|
|
64
59
|
publishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
options: AfRabbitOptions;
|
|
75
|
-
redisClient: any;
|
|
76
|
-
redisLock?: RedisLockType;
|
|
60
|
+
readonly publishConnection: ConnectionData;
|
|
61
|
+
readonly consumeConnection: ConnectionData;
|
|
62
|
+
readonly em: EventEmitter;
|
|
63
|
+
readonly exchanges: ExchangesCache;
|
|
64
|
+
readonly queues: QueuesCache;
|
|
65
|
+
readonly queueSetupPromises: QueueSetupPromisesDictionary;
|
|
66
|
+
readonly assertExchangePromises: AssertExchangePromisesDictionary;
|
|
67
|
+
readonly redisClient?: ReturnType<typeof getRedisInstance>;
|
|
68
|
+
readonly redisLock?: ReturnType<typeof RedisLock>;
|
|
77
69
|
/** Array of consumers tags used for canceling consumption */
|
|
78
|
-
consumersTags: Map<string, {
|
|
70
|
+
readonly consumersTags: Map<string, {
|
|
79
71
|
channel: ConfirmChannel;
|
|
80
72
|
consumerTag: string;
|
|
81
73
|
}>;
|
|
82
|
-
private consumersToRegister;
|
|
74
|
+
private readonly consumersToRegister;
|
|
83
75
|
private doesVHostExist;
|
|
84
|
-
private vhost;
|
|
76
|
+
private readonly vhost;
|
|
85
77
|
private gracefulShutdownStarted;
|
|
86
78
|
oldPublishChannel: ChannelWrapper | null;
|
|
87
79
|
oldPublishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
oldAssertExchangePromises: AssertExchangePromisesDictionary;
|
|
97
|
-
oldConsumersTags: Map<string, {
|
|
80
|
+
readonly oldPublishConnection: ConnectionData;
|
|
81
|
+
readonly oldConsumeConnection: ConnectionData;
|
|
82
|
+
readonly oldEm: EventEmitter;
|
|
83
|
+
readonly oldExchanges: ExchangesCache;
|
|
84
|
+
readonly oldQueues: QueuesCache;
|
|
85
|
+
readonly oldQueueSetupPromises: QueueSetupPromisesDictionary;
|
|
86
|
+
readonly oldAssertExchangePromises: AssertExchangePromisesDictionary;
|
|
87
|
+
readonly oldConsumersTags: Map<string, {
|
|
98
88
|
channel: ConfirmChannel;
|
|
99
89
|
consumerTag: string;
|
|
100
90
|
}>;
|
|
101
|
-
private oldConsumersToRegister;
|
|
102
|
-
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig);
|
|
91
|
+
private readonly oldConsumersToRegister;
|
|
92
|
+
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig | undefined);
|
|
93
|
+
private getRedisKey;
|
|
103
94
|
private assertVHost;
|
|
104
95
|
private shouldConsumeMessageByTimestamp;
|
|
105
|
-
ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: null) => (userMsg: ConsumeMessage) => Promise<
|
|
106
|
-
nack: (channel: ConfirmChannel, queue: string, options:
|
|
96
|
+
ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessage) => Promise<void>;
|
|
97
|
+
nack: (channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessageOrNull, { skipRetry, }?: NackOptions) => Promise<void>;
|
|
107
98
|
getConnection(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
108
|
-
getNewChannel({ name, onClose, options, connection, }: newChannelOpts): Promise<
|
|
99
|
+
getNewChannel({ name, onClose, options, connection, }: newChannelOpts): Promise<ChannelWrapper>;
|
|
109
100
|
assertChannel({ force, connection }: assertChannelOpts): Promise<ChannelWrapper>;
|
|
110
|
-
assertExchange(exchangeName: string, connection: ConnectionData): Promise<
|
|
101
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
111
102
|
getQueueLength(queue: string): Promise<Replies.AssertQueue>;
|
|
112
103
|
private deleteQueue;
|
|
113
104
|
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
114
105
|
setupQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
115
106
|
static shouldUseQuorum(queueName: string): boolean;
|
|
116
|
-
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<
|
|
107
|
+
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
117
108
|
private saveConsumer;
|
|
118
|
-
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<
|
|
119
|
-
consumeNew(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<
|
|
120
|
-
consumeOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<
|
|
109
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
110
|
+
consumeNew(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
111
|
+
consumeOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
121
112
|
private lockRedisIfNeeded;
|
|
122
113
|
private unlockRedisIfNeeded;
|
|
123
114
|
private consumeFromRabbit;
|
|
124
|
-
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<
|
|
125
|
-
publish(exchange: string, content: any, customHeaders?:
|
|
126
|
-
sendToQueue(queue: string, content: any, options?:
|
|
115
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
116
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions['headers'], isQuorumQueue?: boolean): Promise<void>;
|
|
117
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue, customHeaders?: PublishOptions['headers'], isQuorumQueue?: boolean): Promise<boolean | undefined>;
|
|
127
118
|
isConnected(): Promise<boolean>;
|
|
128
119
|
gracefulShutdown(signal: string): Promise<void>;
|
|
129
120
|
private consumeFromRabbitOld;
|
|
130
|
-
getNewChannelOld({ name, onClose, options, connection, }: newChannelOpts): Promise<
|
|
121
|
+
getNewChannelOld({ name, onClose, options, connection, }: newChannelOpts): Promise<ChannelWrapper>;
|
|
131
122
|
getConnectionOld(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
132
123
|
private saveConsumerOld;
|
|
133
|
-
assertQueueOld(queueName: string, options?: Options.AssertQueue): Promise<
|
|
124
|
+
assertQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
134
125
|
setupQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
135
126
|
assertChannelOld({ force, connection }: assertChannelOpts): Promise<ChannelWrapper>;
|
|
136
127
|
private deleteQueueOld;
|
|
137
|
-
assertExchangeOld(exchangeName: string, connection: ConnectionData): Promise<
|
|
128
|
+
assertExchangeOld(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
138
129
|
isConnectedOld(): Promise<boolean>;
|
|
139
130
|
private maskURL;
|
|
140
131
|
}
|