@autofleet/rabbit 4.1.1 → 5.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/README.md +8 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/index-B6pk4Ot8.d.cts +216 -0
- package/dist/index-K1ijaudV.d.ts +216 -0
- package/dist/index.cjs +1119 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -132
- package/dist/index.js +1111 -1112
- package/dist/index.js.map +1 -1
- package/dist/mock/index.cjs +20 -0
- package/dist/mock/index.cjs.map +1 -0
- package/dist/mock/index.d.cts +18 -0
- package/dist/mock/index.d.ts +16 -12
- package/dist/mock/index.js +18 -18
- package/dist/mock/index.js.map +1 -1
- package/dist/mock/vitest.cjs +21 -0
- package/dist/mock/vitest.cjs.map +1 -0
- package/dist/mock/vitest.d.cts +18 -0
- package/dist/mock/vitest.d.ts +16 -11
- package/dist/mock/vitest.js +18 -17
- package/dist/mock/vitest.js.map +1 -1
- package/package.json +48 -9
- package/.nvmrc +0 -1
- package/dist/lib/celery.d.ts +0 -9
- package/dist/lib/celery.js +0 -54
- package/dist/lib/celery.js.map +0 -1
- package/dist/lib/consts.d.ts +0 -27
- package/dist/lib/consts.js +0 -31
- package/dist/lib/consts.js.map +0 -1
- package/dist/lib/rabbitError.d.ts +0 -3
- package/dist/lib/rabbitError.js +0 -10
- package/dist/lib/rabbitError.js.map +0 -1
- package/dist/lib/redis.d.ts +0 -8
- package/dist/lib/redis.js +0 -6
- package/dist/lib/redis.js.map +0 -1
- package/dist/lib/types.d.ts +0 -57
- package/dist/lib/types.js +0 -12
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -14
- package/dist/lib/utils.js +0 -29
- package/dist/lib/utils.js.map +0 -1
- package/dist/logger.d.ts +0 -2
- package/dist/logger.js +0 -9
- package/dist/logger.js.map +0 -1
- package/src/index.ts +0 -1401
- package/src/lib/celery.ts +0 -89
- package/src/lib/consts.ts +0 -32
- package/src/lib/rabbitError.ts +0 -6
- package/src/lib/redis.ts +0 -11
- package/src/lib/types.ts +0 -77
- package/src/lib/utils.ts +0 -42
- package/src/logger.ts +0 -5
- package/src/mock/index.ts +0 -25
- package/src/mock/vitest.ts +0 -24
- package/src/redis-lock.d.ts +0 -6
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -17
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# V5 migration
|
|
2
|
+
|
|
3
|
+
The breaking change in this version is the removal of `zehut` from dependencies and usage as a peer-dependency.
|
|
4
|
+
The required version of zehut is now `^4.0.0`.
|
|
5
|
+
|
|
6
|
+
This was moved to being a peer-dependency in order to ensure that the version of `zehut` used here is the same as used in the MS, and not risk the package using v4 while the service is using v3, which would cause `zehut` to have multiple traces, which will not all hold the correct data.
|
|
7
|
+
|
|
8
|
+
Additionally, the minimum node version is now 18, due to the minimum version of node defined in `zehut`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import RedisLock from "redis-lock";
|
|
3
|
+
import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from "amqp-connection-manager";
|
|
4
|
+
import { PublishOptions } from "amqp-connection-manager/dist/types/ChannelWrapper";
|
|
5
|
+
import { ConfirmChannel, ConsumeMessage, Options, Replies } from "amqplib";
|
|
6
|
+
import { LoggerInstanceManager } from "@autofleet/logger";
|
|
7
|
+
import { createClient } from "redis";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/redis.d.ts
|
|
10
|
+
type RedisConfig = {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number | undefined;
|
|
13
|
+
prefix?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const getRedisInstance: (config: RedisConfig) => ReturnType<typeof createClient>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/lib/types.d.ts
|
|
18
|
+
interface ExchangesCache {
|
|
19
|
+
[key: string]: Replies.AssertExchange | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface QueuesCache {
|
|
22
|
+
[key: string]: Replies.AssertQueue | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface QueueSetupPromisesDictionary {
|
|
25
|
+
[key: string]: Promise<Replies.AssertQueue> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface AssertExchangePromisesDictionary {
|
|
28
|
+
[key: string]: Promise<Replies.AssertExchange> | undefined;
|
|
29
|
+
}
|
|
30
|
+
type CustomMessageHeaders = {
|
|
31
|
+
redisTimestampValidationKey?: string;
|
|
32
|
+
};
|
|
33
|
+
type ConsumeMessageOrNull = ConsumeMessage | null;
|
|
34
|
+
interface ConsumeOptions {
|
|
35
|
+
retries?: number;
|
|
36
|
+
deadMessageTtl?: number;
|
|
37
|
+
messageTtl?: number;
|
|
38
|
+
limit?: number;
|
|
39
|
+
lockTimeout?: number;
|
|
40
|
+
useConsumeWithLock?: boolean;
|
|
41
|
+
auditContext?: any;
|
|
42
|
+
enableRabbitTrace?: boolean;
|
|
43
|
+
isQuorumQueue?: boolean;
|
|
44
|
+
}
|
|
45
|
+
interface NackOptions {
|
|
46
|
+
skipRetry?: boolean;
|
|
47
|
+
}
|
|
48
|
+
type Message = Omit<ConsumeMessage, "content"> & {
|
|
49
|
+
content: any;
|
|
50
|
+
};
|
|
51
|
+
type CallbackFunction = (msg: Message, ack: () => Promise<void>, nack: (ignored: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>) => Promise<void>;
|
|
52
|
+
type ConnectionData = {
|
|
53
|
+
amqpConnection: AmqpConnectionManager | null;
|
|
54
|
+
creatingConnection: boolean;
|
|
55
|
+
connectionCreatedEventName: string;
|
|
56
|
+
connectionFailedEventName: string;
|
|
57
|
+
blockReconnect: boolean;
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/lib/celery.d.ts
|
|
61
|
+
interface TaskData {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
interface SendTaskOptions {
|
|
65
|
+
taskName: string;
|
|
66
|
+
queueName: string;
|
|
67
|
+
}
|
|
68
|
+
declare function sendCeleryTaskViaHttp(data: TaskData, {
|
|
69
|
+
taskName,
|
|
70
|
+
queueName
|
|
71
|
+
}: SendTaskOptions): Promise<void>;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/index.d.ts
|
|
74
|
+
interface IAfRabbitMq {
|
|
75
|
+
ack(channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null): (userMsg: ConsumeMessage) => Promise<void>;
|
|
76
|
+
nack(channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: () => Promise<void>): (userMsg: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>;
|
|
77
|
+
assertChannel(options?: assertChannelOpts): Promise<ChannelWrapper>;
|
|
78
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
79
|
+
assertQueue(queueName: string, options?: Options.AssertQueue | null): Promise<Replies.AssertQueue>;
|
|
80
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
81
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
82
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions["headers"]): Promise<void>;
|
|
83
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue | null, customHeaders?: PublishOptions["headers"]): Promise<boolean | undefined>;
|
|
84
|
+
redisClient?: ReturnType<typeof getRedisInstance>;
|
|
85
|
+
}
|
|
86
|
+
interface AfRabbitOptions {
|
|
87
|
+
disableReconnect?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* When you want your own grace-full shutdown, set this to true.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
dontGracefulShutdown?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* don't retry on creation error
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
dontRetryAssert?: boolean;
|
|
98
|
+
rabbitHost?: string;
|
|
99
|
+
vhost?: string;
|
|
100
|
+
logger?: LoggerInstanceManager;
|
|
101
|
+
}
|
|
102
|
+
type newChannelOpts = {
|
|
103
|
+
name?: string;
|
|
104
|
+
onClose?: null | ((args: any | null) => void);
|
|
105
|
+
options?: CreateChannelOpts | undefined;
|
|
106
|
+
connection: ConnectionData;
|
|
107
|
+
};
|
|
108
|
+
type assertChannelOpts = {
|
|
109
|
+
channelName?: string;
|
|
110
|
+
force?: boolean;
|
|
111
|
+
connection: ConnectionData;
|
|
112
|
+
};
|
|
113
|
+
declare class RabbitMq implements IAfRabbitMq {
|
|
114
|
+
#private;
|
|
115
|
+
readonly options: AfRabbitOptions;
|
|
116
|
+
private readonly redisConfig?;
|
|
117
|
+
static parseMsg(msg: ConsumeMessage): Message;
|
|
118
|
+
static validateName(type: string, name: string): void;
|
|
119
|
+
static getPublishOptions(customHeaders?: CustomMessageHeaders): PublishOptions;
|
|
120
|
+
readonly DISCONNECT_MSG = "rabbit: connection disconnect";
|
|
121
|
+
readonly RECONNECT_MSG = "rabbit: connection disconnect - reconnecting";
|
|
122
|
+
publishChannel: ChannelWrapper | null;
|
|
123
|
+
publishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
124
|
+
readonly publishConnection: ConnectionData;
|
|
125
|
+
readonly consumeConnection: ConnectionData;
|
|
126
|
+
readonly em: EventEmitter;
|
|
127
|
+
readonly exchanges: ExchangesCache;
|
|
128
|
+
readonly queues: QueuesCache;
|
|
129
|
+
readonly queueSetupPromises: QueueSetupPromisesDictionary;
|
|
130
|
+
readonly assertExchangePromises: AssertExchangePromisesDictionary;
|
|
131
|
+
readonly redisClient?: ReturnType<typeof getRedisInstance>;
|
|
132
|
+
readonly redisLock?: ReturnType<typeof RedisLock>;
|
|
133
|
+
/** A map of consumers' tags used for canceling consumption */
|
|
134
|
+
readonly consumersTags: Map<string, {
|
|
135
|
+
channel: ConfirmChannel;
|
|
136
|
+
consumerTag: string;
|
|
137
|
+
}>;
|
|
138
|
+
private readonly consumersToRegister;
|
|
139
|
+
private doesVHostExist;
|
|
140
|
+
private readonly vhost;
|
|
141
|
+
private gracefulShutdownStarted;
|
|
142
|
+
oldPublishChannel: ChannelWrapper | null;
|
|
143
|
+
oldPublishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
144
|
+
readonly oldPublishConnection: ConnectionData;
|
|
145
|
+
readonly oldConsumeConnection: ConnectionData;
|
|
146
|
+
readonly oldEm: EventEmitter;
|
|
147
|
+
readonly oldExchanges: ExchangesCache;
|
|
148
|
+
readonly oldQueues: QueuesCache;
|
|
149
|
+
readonly oldQueueSetupPromises: QueueSetupPromisesDictionary;
|
|
150
|
+
readonly oldAssertExchangePromises: AssertExchangePromisesDictionary;
|
|
151
|
+
readonly oldConsumersTags: Map<string, {
|
|
152
|
+
channel: ConfirmChannel;
|
|
153
|
+
consumerTag: string;
|
|
154
|
+
}>;
|
|
155
|
+
private readonly oldConsumersToRegister;
|
|
156
|
+
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig | undefined);
|
|
157
|
+
private getRedisKey;
|
|
158
|
+
private assertVHost;
|
|
159
|
+
private shouldConsumeMessageByTimestamp;
|
|
160
|
+
ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessage) => Promise<void>;
|
|
161
|
+
nack: (channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessageOrNull, {
|
|
162
|
+
skipRetry
|
|
163
|
+
}?: NackOptions) => Promise<void>;
|
|
164
|
+
getConnection(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
165
|
+
getNewChannel({
|
|
166
|
+
name,
|
|
167
|
+
onClose,
|
|
168
|
+
options,
|
|
169
|
+
connection
|
|
170
|
+
}: newChannelOpts): Promise<ChannelWrapper>;
|
|
171
|
+
assertChannel({
|
|
172
|
+
force,
|
|
173
|
+
connection
|
|
174
|
+
}: assertChannelOpts): Promise<ChannelWrapper>;
|
|
175
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
176
|
+
getQueueLength(queue: string): Promise<Replies.AssertQueue>;
|
|
177
|
+
private deleteQueue;
|
|
178
|
+
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
179
|
+
setupQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
180
|
+
static shouldUseQuorum(queueName: string): boolean;
|
|
181
|
+
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
182
|
+
private saveConsumer;
|
|
183
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
184
|
+
consumeNew(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
185
|
+
consumeOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
186
|
+
private lockRedisIfNeeded;
|
|
187
|
+
private unlockRedisIfNeeded;
|
|
188
|
+
private consumeFromRabbit;
|
|
189
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
190
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions["headers"], isQuorumQueue?: boolean): Promise<void>;
|
|
191
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue, customHeaders?: PublishOptions["headers"], isQuorumQueue?: boolean): Promise<boolean | undefined>;
|
|
192
|
+
isConnected(): Promise<boolean>;
|
|
193
|
+
gracefulShutdown(signal: string): Promise<void>;
|
|
194
|
+
private consumeFromRabbitOld;
|
|
195
|
+
getNewChannelOld({
|
|
196
|
+
name,
|
|
197
|
+
onClose,
|
|
198
|
+
options,
|
|
199
|
+
connection
|
|
200
|
+
}: newChannelOpts): Promise<ChannelWrapper>;
|
|
201
|
+
getConnectionOld(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
202
|
+
private saveConsumerOld;
|
|
203
|
+
assertQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
204
|
+
setupQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
205
|
+
assertChannelOld({
|
|
206
|
+
force,
|
|
207
|
+
connection
|
|
208
|
+
}: assertChannelOpts): Promise<ChannelWrapper>;
|
|
209
|
+
private deleteQueueOld;
|
|
210
|
+
assertExchangeOld(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
211
|
+
isConnectedOld(): Promise<boolean>;
|
|
212
|
+
private maskURL;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { AfRabbitOptions, IAfRabbitMq, RabbitMq, sendCeleryTaskViaHttp };
|
|
216
|
+
//# sourceMappingURL=index-B6pk4Ot8.d.cts.map
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import RedisLock from "redis-lock";
|
|
3
|
+
import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from "amqp-connection-manager";
|
|
4
|
+
import { LoggerInstanceManager } from "@autofleet/logger";
|
|
5
|
+
import { createClient } from "redis";
|
|
6
|
+
import { PublishOptions } from "amqp-connection-manager/dist/types/ChannelWrapper";
|
|
7
|
+
import { ConfirmChannel, ConsumeMessage, Options, Replies } from "amqplib";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/redis.d.ts
|
|
10
|
+
type RedisConfig = {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number | undefined;
|
|
13
|
+
prefix?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const getRedisInstance: (config: RedisConfig) => ReturnType<typeof createClient>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/lib/types.d.ts
|
|
18
|
+
interface ExchangesCache {
|
|
19
|
+
[key: string]: Replies.AssertExchange | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface QueuesCache {
|
|
22
|
+
[key: string]: Replies.AssertQueue | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface QueueSetupPromisesDictionary {
|
|
25
|
+
[key: string]: Promise<Replies.AssertQueue> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface AssertExchangePromisesDictionary {
|
|
28
|
+
[key: string]: Promise<Replies.AssertExchange> | undefined;
|
|
29
|
+
}
|
|
30
|
+
type CustomMessageHeaders = {
|
|
31
|
+
redisTimestampValidationKey?: string;
|
|
32
|
+
};
|
|
33
|
+
type ConsumeMessageOrNull = ConsumeMessage | null;
|
|
34
|
+
interface ConsumeOptions {
|
|
35
|
+
retries?: number;
|
|
36
|
+
deadMessageTtl?: number;
|
|
37
|
+
messageTtl?: number;
|
|
38
|
+
limit?: number;
|
|
39
|
+
lockTimeout?: number;
|
|
40
|
+
useConsumeWithLock?: boolean;
|
|
41
|
+
auditContext?: any;
|
|
42
|
+
enableRabbitTrace?: boolean;
|
|
43
|
+
isQuorumQueue?: boolean;
|
|
44
|
+
}
|
|
45
|
+
interface NackOptions {
|
|
46
|
+
skipRetry?: boolean;
|
|
47
|
+
}
|
|
48
|
+
type Message = Omit<ConsumeMessage, "content"> & {
|
|
49
|
+
content: any;
|
|
50
|
+
};
|
|
51
|
+
type CallbackFunction = (msg: Message, ack: () => Promise<void>, nack: (ignored: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>) => Promise<void>;
|
|
52
|
+
type ConnectionData = {
|
|
53
|
+
amqpConnection: AmqpConnectionManager | null;
|
|
54
|
+
creatingConnection: boolean;
|
|
55
|
+
connectionCreatedEventName: string;
|
|
56
|
+
connectionFailedEventName: string;
|
|
57
|
+
blockReconnect: boolean;
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/lib/celery.d.ts
|
|
61
|
+
interface TaskData {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
interface SendTaskOptions {
|
|
65
|
+
taskName: string;
|
|
66
|
+
queueName: string;
|
|
67
|
+
}
|
|
68
|
+
declare function sendCeleryTaskViaHttp(data: TaskData, {
|
|
69
|
+
taskName,
|
|
70
|
+
queueName
|
|
71
|
+
}: SendTaskOptions): Promise<void>;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/index.d.ts
|
|
74
|
+
interface IAfRabbitMq {
|
|
75
|
+
ack(channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null): (userMsg: ConsumeMessage) => Promise<void>;
|
|
76
|
+
nack(channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: () => Promise<void>): (userMsg: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>;
|
|
77
|
+
assertChannel(options?: assertChannelOpts): Promise<ChannelWrapper>;
|
|
78
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
79
|
+
assertQueue(queueName: string, options?: Options.AssertQueue | null): Promise<Replies.AssertQueue>;
|
|
80
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
81
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
82
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions["headers"]): Promise<void>;
|
|
83
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue | null, customHeaders?: PublishOptions["headers"]): Promise<boolean | undefined>;
|
|
84
|
+
redisClient?: ReturnType<typeof getRedisInstance>;
|
|
85
|
+
}
|
|
86
|
+
interface AfRabbitOptions {
|
|
87
|
+
disableReconnect?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* When you want your own grace-full shutdown, set this to true.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
dontGracefulShutdown?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* don't retry on creation error
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
dontRetryAssert?: boolean;
|
|
98
|
+
rabbitHost?: string;
|
|
99
|
+
vhost?: string;
|
|
100
|
+
logger?: LoggerInstanceManager;
|
|
101
|
+
}
|
|
102
|
+
type newChannelOpts = {
|
|
103
|
+
name?: string;
|
|
104
|
+
onClose?: null | ((args: any | null) => void);
|
|
105
|
+
options?: CreateChannelOpts | undefined;
|
|
106
|
+
connection: ConnectionData;
|
|
107
|
+
};
|
|
108
|
+
type assertChannelOpts = {
|
|
109
|
+
channelName?: string;
|
|
110
|
+
force?: boolean;
|
|
111
|
+
connection: ConnectionData;
|
|
112
|
+
};
|
|
113
|
+
declare class RabbitMq implements IAfRabbitMq {
|
|
114
|
+
#private;
|
|
115
|
+
readonly options: AfRabbitOptions;
|
|
116
|
+
private readonly redisConfig?;
|
|
117
|
+
static parseMsg(msg: ConsumeMessage): Message;
|
|
118
|
+
static validateName(type: string, name: string): void;
|
|
119
|
+
static getPublishOptions(customHeaders?: CustomMessageHeaders): PublishOptions;
|
|
120
|
+
readonly DISCONNECT_MSG = "rabbit: connection disconnect";
|
|
121
|
+
readonly RECONNECT_MSG = "rabbit: connection disconnect - reconnecting";
|
|
122
|
+
publishChannel: ChannelWrapper | null;
|
|
123
|
+
publishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
124
|
+
readonly publishConnection: ConnectionData;
|
|
125
|
+
readonly consumeConnection: ConnectionData;
|
|
126
|
+
readonly em: EventEmitter;
|
|
127
|
+
readonly exchanges: ExchangesCache;
|
|
128
|
+
readonly queues: QueuesCache;
|
|
129
|
+
readonly queueSetupPromises: QueueSetupPromisesDictionary;
|
|
130
|
+
readonly assertExchangePromises: AssertExchangePromisesDictionary;
|
|
131
|
+
readonly redisClient?: ReturnType<typeof getRedisInstance>;
|
|
132
|
+
readonly redisLock?: ReturnType<typeof RedisLock>;
|
|
133
|
+
/** A map of consumers' tags used for canceling consumption */
|
|
134
|
+
readonly consumersTags: Map<string, {
|
|
135
|
+
channel: ConfirmChannel;
|
|
136
|
+
consumerTag: string;
|
|
137
|
+
}>;
|
|
138
|
+
private readonly consumersToRegister;
|
|
139
|
+
private doesVHostExist;
|
|
140
|
+
private readonly vhost;
|
|
141
|
+
private gracefulShutdownStarted;
|
|
142
|
+
oldPublishChannel: ChannelWrapper | null;
|
|
143
|
+
oldPublishChannelSetupPromise: Promise<ChannelWrapper> | null;
|
|
144
|
+
readonly oldPublishConnection: ConnectionData;
|
|
145
|
+
readonly oldConsumeConnection: ConnectionData;
|
|
146
|
+
readonly oldEm: EventEmitter;
|
|
147
|
+
readonly oldExchanges: ExchangesCache;
|
|
148
|
+
readonly oldQueues: QueuesCache;
|
|
149
|
+
readonly oldQueueSetupPromises: QueueSetupPromisesDictionary;
|
|
150
|
+
readonly oldAssertExchangePromises: AssertExchangePromisesDictionary;
|
|
151
|
+
readonly oldConsumersTags: Map<string, {
|
|
152
|
+
channel: ConfirmChannel;
|
|
153
|
+
consumerTag: string;
|
|
154
|
+
}>;
|
|
155
|
+
private readonly oldConsumersToRegister;
|
|
156
|
+
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig | undefined);
|
|
157
|
+
private getRedisKey;
|
|
158
|
+
private assertVHost;
|
|
159
|
+
private shouldConsumeMessageByTimestamp;
|
|
160
|
+
ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessage) => Promise<void>;
|
|
161
|
+
nack: (channel: ConfirmChannel, queue: string, options: ConsumeOptions, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock?: (() => Promise<void>) | null) => (userMsg: ConsumeMessageOrNull, {
|
|
162
|
+
skipRetry
|
|
163
|
+
}?: NackOptions) => Promise<void>;
|
|
164
|
+
getConnection(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
165
|
+
getNewChannel({
|
|
166
|
+
name,
|
|
167
|
+
onClose,
|
|
168
|
+
options,
|
|
169
|
+
connection
|
|
170
|
+
}: newChannelOpts): Promise<ChannelWrapper>;
|
|
171
|
+
assertChannel({
|
|
172
|
+
force,
|
|
173
|
+
connection
|
|
174
|
+
}: assertChannelOpts): Promise<ChannelWrapper>;
|
|
175
|
+
assertExchange(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
176
|
+
getQueueLength(queue: string): Promise<Replies.AssertQueue>;
|
|
177
|
+
private deleteQueue;
|
|
178
|
+
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
179
|
+
setupQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
180
|
+
static shouldUseQuorum(queueName: string): boolean;
|
|
181
|
+
assertQueue(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
182
|
+
private saveConsumer;
|
|
183
|
+
consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
184
|
+
consumeNew(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
185
|
+
consumeOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
186
|
+
private lockRedisIfNeeded;
|
|
187
|
+
private unlockRedisIfNeeded;
|
|
188
|
+
private consumeFromRabbit;
|
|
189
|
+
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<void>;
|
|
190
|
+
publish(exchange: string, content: any, customHeaders?: PublishOptions["headers"], isQuorumQueue?: boolean): Promise<void>;
|
|
191
|
+
sendToQueue(queue: string, content: any, options?: Options.AssertQueue, customHeaders?: PublishOptions["headers"], isQuorumQueue?: boolean): Promise<boolean | undefined>;
|
|
192
|
+
isConnected(): Promise<boolean>;
|
|
193
|
+
gracefulShutdown(signal: string): Promise<void>;
|
|
194
|
+
private consumeFromRabbitOld;
|
|
195
|
+
getNewChannelOld({
|
|
196
|
+
name,
|
|
197
|
+
onClose,
|
|
198
|
+
options,
|
|
199
|
+
connection
|
|
200
|
+
}: newChannelOpts): Promise<ChannelWrapper>;
|
|
201
|
+
getConnectionOld(connection: ConnectionData): Promise<AmqpConnectionManager>;
|
|
202
|
+
private saveConsumerOld;
|
|
203
|
+
assertQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
204
|
+
setupQueueOld(queueName: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
|
|
205
|
+
assertChannelOld({
|
|
206
|
+
force,
|
|
207
|
+
connection
|
|
208
|
+
}: assertChannelOpts): Promise<ChannelWrapper>;
|
|
209
|
+
private deleteQueueOld;
|
|
210
|
+
assertExchangeOld(exchangeName: string, connection: ConnectionData): Promise<Replies.AssertExchange>;
|
|
211
|
+
isConnectedOld(): Promise<boolean>;
|
|
212
|
+
private maskURL;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { AfRabbitOptions, IAfRabbitMq, RabbitMq, sendCeleryTaskViaHttp };
|
|
216
|
+
//# sourceMappingURL=index-K1ijaudV.d.ts.map
|