@imqueue/core 2.0.25 → 3.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/.oxfmtrc.json +9 -0
- package/.oxlintrc.json +20 -0
- package/README.md +73 -63
- package/debug_getter.d.ts +1 -9
- package/index.d.ts +0 -1
- package/index.js +8 -9
- package/package.json +20 -67
- package/scripts/strip-comment-coverage.mjs +397 -0
- package/src/ClusterManager.d.ts +12 -3
- package/src/ClusterManager.js +21 -10
- package/src/ClusteredRedisQueue.d.ts +46 -14
- package/src/ClusteredRedisQueue.js +196 -169
- package/src/IMessageQueue.d.ts +89 -96
- package/src/IMessageQueue.js +2 -2
- package/src/RedisQueue.d.ts +193 -97
- package/src/RedisQueue.js +1328 -1070
- package/src/UDPClusterManager.d.ts +110 -26
- package/src/UDPClusterManager.js +227 -70
- package/src/UDPWorker.d.ts +53 -1
- package/src/UDPWorker.js +87 -46
- package/src/{promisify.d.ts → helpers/buildOptions.d.ts} +8 -15
- package/src/helpers/buildOptions.js +39 -0
- package/src/{copyEventEmitter.d.ts → helpers/copyEventEmitter.d.ts} +1 -1
- package/src/{copyEventEmitter.js → helpers/copyEventEmitter.js} +3 -4
- package/src/helpers/envInt.d.ts +32 -0
- package/src/helpers/envInt.js +39 -0
- package/src/helpers/escapeRegExp.d.ts +30 -0
- package/src/helpers/escapeRegExp.js +36 -0
- package/src/helpers/index.d.ts +31 -0
- package/src/helpers/index.js +48 -0
- package/src/helpers/pack.d.ts +7 -0
- package/src/helpers/pack.js +37 -0
- package/src/helpers/randomInt.d.ts +31 -0
- package/src/helpers/randomInt.js +37 -0
- package/src/helpers/sha1.d.ts +7 -0
- package/src/helpers/sha1.js +39 -0
- package/src/helpers/unpack.d.ts +7 -0
- package/src/helpers/unpack.js +37 -0
- package/src/index.d.ts +1 -14
- package/src/index.js +1 -19
- package/src/profile.d.ts +28 -38
- package/src/profile.js +100 -95
- package/src/redis.d.ts +1 -1
- package/src/redis.js +4 -2
- package/typedoc.json +19 -0
- package/eslint.config.mjs +0 -98
- package/src/promisify.js +0 -106
- package/src/uuid.d.ts +0 -6
- package/src/uuid.js +0 -65
package/src/IMessageQueue.d.ts
CHANGED
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* purchase a proprietary commercial license. Please contact us at
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
|
-
import { EventEmitter } from 'events';
|
|
24
|
+
import { EventEmitter } from 'node:events';
|
|
25
25
|
import { IMQMode } from './IMQMode';
|
|
26
26
|
import { ClusterManager } from './ClusterManager';
|
|
27
|
-
export { EventEmitter } from 'events';
|
|
27
|
+
export { EventEmitter } from 'node:events';
|
|
28
28
|
/**
|
|
29
29
|
* Represents any JSON-serializable value
|
|
30
30
|
*/
|
|
@@ -40,13 +40,6 @@ export interface JsonObject {
|
|
|
40
40
|
*/
|
|
41
41
|
export interface JsonArray extends Array<AnyJson> {
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Alias for JsonObject, legacy, outdated, deprecated, try to avoid using.
|
|
45
|
-
* Stands here for backward-compatibility only
|
|
46
|
-
*
|
|
47
|
-
* @deprecated
|
|
48
|
-
*/
|
|
49
|
-
export type IJson = JsonObject;
|
|
50
43
|
/**
|
|
51
44
|
* Logger interface
|
|
52
45
|
*/
|
|
@@ -54,30 +47,30 @@ export interface ILogger {
|
|
|
54
47
|
/**
|
|
55
48
|
* Log level function
|
|
56
49
|
*
|
|
57
|
-
* @param {...
|
|
50
|
+
* @param {...unknown[]} args
|
|
58
51
|
*/
|
|
59
|
-
log(...args:
|
|
52
|
+
log(...args: unknown[]): void;
|
|
60
53
|
/**
|
|
61
54
|
* Info level function
|
|
62
55
|
*
|
|
63
|
-
* @param {...
|
|
56
|
+
* @param {...unknown[]} args
|
|
64
57
|
*/
|
|
65
|
-
info(...args:
|
|
58
|
+
info(...args: unknown[]): void;
|
|
66
59
|
/**
|
|
67
60
|
* Warning level function
|
|
68
61
|
*
|
|
69
|
-
* @param {...
|
|
62
|
+
* @param {...unknown[]} args
|
|
70
63
|
*/
|
|
71
|
-
warn(...args:
|
|
64
|
+
warn(...args: unknown[]): void;
|
|
72
65
|
/**
|
|
73
66
|
* Error level function
|
|
74
67
|
*
|
|
75
|
-
* @param {...
|
|
68
|
+
* @param {...unknown[]} args
|
|
76
69
|
*/
|
|
77
|
-
error(...args:
|
|
70
|
+
error(...args: unknown[]): void;
|
|
78
71
|
}
|
|
79
72
|
/**
|
|
80
|
-
* Defines message format.
|
|
73
|
+
* Defines a message format.
|
|
81
74
|
*
|
|
82
75
|
* @type {IMessage}
|
|
83
76
|
*/
|
|
@@ -172,8 +165,7 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
172
165
|
*/
|
|
173
166
|
cleanup: boolean;
|
|
174
167
|
/**
|
|
175
|
-
*
|
|
176
|
-
* which should be removed during cleanup processing
|
|
168
|
+
* Cleanup pattern for queue names that should be removed during cleanup
|
|
177
169
|
*
|
|
178
170
|
* @type {string}
|
|
179
171
|
*/
|
|
@@ -191,41 +183,38 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
191
183
|
*/
|
|
192
184
|
prefix?: string;
|
|
193
185
|
/**
|
|
194
|
-
* Logger
|
|
186
|
+
* Logger instance to use for message queue logging at runtime
|
|
195
187
|
*
|
|
196
188
|
* @type {ILogger}
|
|
197
189
|
*/
|
|
198
190
|
logger?: ILogger;
|
|
199
191
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* queue operations.
|
|
192
|
+
* Delay period (in milliseconds) between watcher availability checks.
|
|
193
|
+
* Used to ensure at least one watcher is available for queue operations.
|
|
203
194
|
*
|
|
204
195
|
* @type {number}
|
|
205
196
|
*/
|
|
206
197
|
watcherCheckDelay?: number;
|
|
207
198
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* and queue host application
|
|
199
|
+
* Enable message compression for serialization. Increases a worker CPU load
|
|
200
|
+
* but decreases network traffic between workers and the queue host.
|
|
211
201
|
*
|
|
212
202
|
* @type {boolean}
|
|
213
203
|
*/
|
|
214
204
|
useGzip?: boolean;
|
|
215
205
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* is not required unless it is required by a system design.
|
|
206
|
+
* Enable guaranteed message delivery. When enabled, uses a more complex
|
|
207
|
+
* algorithm for message handling, ensuring that if a worker fails, the
|
|
208
|
+
* message will be delivered to another worker. Required only for systems
|
|
209
|
+
* that demand guaranteed delivery semantics.
|
|
221
210
|
*
|
|
222
211
|
* @type {boolean}
|
|
223
212
|
*/
|
|
224
213
|
safeDelivery?: boolean;
|
|
225
214
|
/**
|
|
226
|
-
* Time-to-live
|
|
227
|
-
*
|
|
228
|
-
*
|
|
215
|
+
* Time-to-live (in milliseconds) for messages in worker queues. After this
|
|
216
|
+
* period, unacknowledged messages return to the main queue for reprocessing
|
|
217
|
+
* if the worker died. Only effective when safeDelivery is enabled.
|
|
229
218
|
*
|
|
230
219
|
* @type {number}
|
|
231
220
|
*/
|
|
@@ -243,6 +232,15 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
243
232
|
* @type {ClusterManager[]}
|
|
244
233
|
*/
|
|
245
234
|
clusterManagers?: ClusterManager[];
|
|
235
|
+
/**
|
|
236
|
+
* Enable process signal handling (SIGTERM, SIGINT, SIGABRT) by the queue.
|
|
237
|
+
* When enabled, the queue releases its watcher lock and exits gracefully
|
|
238
|
+
* on these signals. Disable if the host application manages shutdown.
|
|
239
|
+
*
|
|
240
|
+
* @default true
|
|
241
|
+
* @type {boolean}
|
|
242
|
+
*/
|
|
243
|
+
handleSignals?: boolean;
|
|
246
244
|
/**
|
|
247
245
|
* Enables/disables verbose logging
|
|
248
246
|
*
|
|
@@ -261,7 +259,7 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
261
259
|
verboseExtended?: boolean;
|
|
262
260
|
}
|
|
263
261
|
export interface EventMap {
|
|
264
|
-
message: [data:
|
|
262
|
+
message: [data: JsonObject, id: string, from: string];
|
|
265
263
|
error: [error: Error, eventName: string];
|
|
266
264
|
}
|
|
267
265
|
export type IMessageQueueConstructor = new (name: string, options?: Partial<IMQOptions>, mode?: IMQMode) => IMessageQueue;
|
|
@@ -270,117 +268,112 @@ export type IMessageQueueConstructor = new (name: string, options?: Partial<IMQO
|
|
|
270
268
|
*
|
|
271
269
|
* @example
|
|
272
270
|
* ~~~typescript
|
|
273
|
-
* import { IMessageQueue, EventEmitter
|
|
271
|
+
* import { IMessageQueue, EventEmitter } from '@imqueue/core';
|
|
272
|
+
* import { randomUUID } from 'node:crypto';
|
|
274
273
|
*
|
|
275
|
-
* class SomeMQAdapter implements IMessageQueue
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
274
|
+
* class SomeMQAdapter extends EventEmitter implements IMessageQueue {
|
|
275
|
+
* public async start(): Promise<SomeMQAdapter> {
|
|
276
|
+
* // ... implementation goes here
|
|
277
|
+
* return this;
|
|
278
|
+
* }
|
|
279
|
+
* public async stop(): Promise<SomeMQAdapter> {
|
|
280
|
+
* // ... implementation goes here
|
|
281
|
+
* return this;
|
|
282
|
+
* }
|
|
283
|
+
* public async send(
|
|
284
|
+
* toQueue: string,
|
|
285
|
+
* message: JsonObject,
|
|
286
|
+
* delay?: number,
|
|
287
|
+
* ): Promise<string> {
|
|
288
|
+
* const messageId = randomUUID();
|
|
289
|
+
* // ... implementation goes here
|
|
290
|
+
* return messageId;
|
|
291
|
+
* }
|
|
292
|
+
* public async destroy(): Promise<void> {
|
|
293
|
+
* // ... implementation goes here
|
|
294
|
+
* }
|
|
295
|
+
* public async clear(): Promise<SomeMQAdapter> {
|
|
296
|
+
* // ... implementation goes here
|
|
297
|
+
* return this;
|
|
298
|
+
* }
|
|
300
299
|
* }
|
|
301
300
|
* ~~~
|
|
302
301
|
*/
|
|
303
302
|
export interface IMessageQueue extends EventEmitter<EventMap> {
|
|
304
303
|
/**
|
|
305
|
-
* Message event. Occurs every time queue
|
|
304
|
+
* Message event. Occurs every time the queue receives a message.
|
|
306
305
|
*
|
|
307
306
|
* @event IMessageQueue#message
|
|
308
307
|
* @type {JsonObject} message - message data
|
|
309
308
|
* @type {string} id - message identifier
|
|
310
|
-
* @type {string} from - source queue produced the message
|
|
309
|
+
* @type {string} from - source queue that produced the message
|
|
311
310
|
*/
|
|
312
311
|
/**
|
|
313
|
-
* Error event. Occurs every time queue
|
|
312
|
+
* Error event. Occurs every time the queue encounters an error.
|
|
314
313
|
*
|
|
315
314
|
* @event IMessageQueue#error
|
|
316
|
-
* @type {Error} err - error caught by message queue
|
|
315
|
+
* @type {Error} err - error caught by the message queue
|
|
317
316
|
* @type {string} code - message queue error code
|
|
318
317
|
*/
|
|
319
318
|
/**
|
|
320
319
|
* Starts the messaging queue.
|
|
321
|
-
* Supposed to be an async function.
|
|
322
320
|
*
|
|
323
321
|
* @returns {Promise<IMessageQueue>}
|
|
324
322
|
*/
|
|
325
323
|
start(): Promise<IMessageQueue>;
|
|
326
324
|
/**
|
|
327
|
-
* Stops the queue
|
|
328
|
-
* Supposed to be an async function.
|
|
325
|
+
* Stops the queue from handling messages.
|
|
329
326
|
*
|
|
330
327
|
* @returns {Promise<IMessageQueue>}
|
|
331
328
|
*/
|
|
332
329
|
stop(): Promise<IMessageQueue>;
|
|
333
330
|
/**
|
|
334
|
-
* Sends a message to
|
|
335
|
-
* Supposed to be an async function.
|
|
331
|
+
* Sends a message to the specified queue with the given data.
|
|
336
332
|
*
|
|
337
|
-
* @param {string} toQueue -
|
|
338
|
-
* @param {JsonObject} message - message data
|
|
339
|
-
* @param {number} [delay] - if specified, message will be handled in
|
|
340
|
-
*
|
|
341
|
-
* @param {(err: Error) => void} [errorHandler] - callback
|
|
342
|
-
*
|
|
343
|
-
* @returns {Promise<string>} - message identifier
|
|
333
|
+
* @param {string} toQueue - name of the destination queue
|
|
334
|
+
* @param {JsonObject} message - message data to send
|
|
335
|
+
* @param {number} [delay] - if specified, the message will be handled in
|
|
336
|
+
* the target queue after the specified delay in milliseconds
|
|
337
|
+
* @param {(err: Error) => void} [errorHandler] - callback invoked only
|
|
338
|
+
* when an internal error occurs during message send execution
|
|
339
|
+
* @returns {Promise<string>} - the message identifier
|
|
344
340
|
*/
|
|
345
341
|
send(toQueue: string, message: JsonObject, delay?: number, errorHandler?: (err: Error) => void): Promise<string>;
|
|
346
342
|
/**
|
|
347
|
-
* Creates or uses subscription channel with the given name and sets
|
|
343
|
+
* Creates or uses a subscription channel with the given name and sets
|
|
348
344
|
* message handler on data receive
|
|
349
345
|
*
|
|
350
346
|
* @param {string} channel - channel name
|
|
351
|
-
* @param {(data: JsonObject) =>
|
|
347
|
+
* @param {(data: JsonObject) => void} handler
|
|
352
348
|
*/
|
|
353
|
-
subscribe(channel: string, handler: (data: JsonObject) =>
|
|
349
|
+
subscribe(channel: string, handler: (data: JsonObject) => void): Promise<void>;
|
|
354
350
|
/**
|
|
355
|
-
* Closes subscription channel
|
|
351
|
+
* Closes the subscription channel
|
|
356
352
|
*
|
|
357
|
-
* @
|
|
353
|
+
* @returns {Promise<void>}
|
|
358
354
|
*/
|
|
359
355
|
unsubscribe(): Promise<void>;
|
|
360
356
|
/**
|
|
361
|
-
* Publishes data to current queue channel
|
|
357
|
+
* Publishes data to the current queue channel
|
|
362
358
|
*
|
|
363
|
-
* If toName specified
|
|
364
|
-
* can be used to
|
|
365
|
-
*
|
|
366
|
-
* (same imq prefix)
|
|
359
|
+
* If toName is specified, publishes to a pubsub with a different name. This
|
|
360
|
+
* can be used to broadcast messages to other subscribers on different pubsub
|
|
361
|
+
* channels. Different names must be in the same namespace (same imq prefix).
|
|
367
362
|
*
|
|
368
|
-
* @param {JsonObject} data - data to publish as channel message
|
|
369
|
-
* @param {string} [toName] - different name
|
|
370
|
-
* @
|
|
363
|
+
* @param {JsonObject} data - data to publish as a channel message
|
|
364
|
+
* @param {string} [toName] - optional different pubsub name to publish to
|
|
365
|
+
* @returns {Promise<void>}
|
|
371
366
|
*/
|
|
372
367
|
publish(data: JsonObject, toName?: string): Promise<void>;
|
|
373
368
|
/**
|
|
374
|
-
* Safely destroys current queue,
|
|
375
|
-
*
|
|
376
|
-
* Supposed to be an async function.
|
|
369
|
+
* Safely destroys the current queue, unregistering all event listeners
|
|
370
|
+
* and closing connections.
|
|
377
371
|
*
|
|
378
372
|
* @returns {Promise<void>}
|
|
379
373
|
*/
|
|
380
374
|
destroy(): Promise<void>;
|
|
381
375
|
/**
|
|
382
|
-
* Clears queue data
|
|
383
|
-
* Supposed to be an async function.
|
|
376
|
+
* Clears all queue data from the queue host application.
|
|
384
377
|
*
|
|
385
378
|
* @returns {Promise<IMessageQueue>}
|
|
386
379
|
*/
|
package/src/IMessageQueue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventEmitter = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return
|
|
4
|
+
var node_events_1 = require("node:events");
|
|
5
|
+
Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return node_events_1.EventEmitter; } });
|
|
6
6
|
//# sourceMappingURL=IMessageQueue.js.map
|