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