@imqueue/core 3.4.2 → 3.5.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/AGENTS.md +48 -9
- package/CHANGELOG.md +186 -0
- package/README.md +225 -0
- package/SECURITY.md +28 -0
- package/index.d.ts +10 -2
- package/index.js +10 -2
- package/package.json +5 -4
- package/src/ClusterManager.d.ts +5 -0
- package/src/ClusterManager.js +5 -0
- package/src/ClusteredRedisQueue.d.ts +62 -0
- package/src/ClusteredRedisQueue.js +69 -0
- package/src/IMessageQueue.d.ts +145 -51
- package/src/RedisQueue.d.ts +251 -58
- package/src/RedisQueue.js +412 -98
- package/src/UDPClusterManager.d.ts +35 -0
- package/src/UDPClusterManager.js +35 -0
- package/src/UDPWorker.d.ts +134 -1
- package/src/UDPWorker.js +140 -1
- package/src/helpers/copyEventEmitter.d.ts +21 -0
- package/src/helpers/copyEventEmitter.js +21 -0
- package/src/helpers/envTls.d.ts +31 -0
- package/src/helpers/envTls.js +158 -0
- package/src/helpers/index.d.ts +2 -0
- package/src/helpers/index.js +2 -0
- package/src/helpers/tlsFingerprint.d.ts +15 -0
- package/src/helpers/tlsFingerprint.js +88 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/redis.d.ts +6 -0
- package/CLAUDE.md +0 -2
|
@@ -127,7 +127,21 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
|
|
|
127
127
|
* cluster servers
|
|
128
128
|
*/
|
|
129
129
|
private readonly clusterEmitter;
|
|
130
|
+
/**
|
|
131
|
+
* What has been done to this queue so far, so that a server joining later
|
|
132
|
+
* can be brought to the same point.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Cluster membership changes at runtime, so a per-host queue may be created
|
|
136
|
+
* long after `start()` and `subscribe()` were called on the cluster. This
|
|
137
|
+
* records those calls; {@link ClusteredRedisQueue.initializeQueue} replays
|
|
138
|
+
* them onto each new queue.
|
|
139
|
+
*/
|
|
130
140
|
private state;
|
|
141
|
+
/**
|
|
142
|
+
* Handles for the cluster managers this queue is registered with, kept so
|
|
143
|
+
* that {@link ClusteredRedisQueue.destroy} can deregister from each.
|
|
144
|
+
*/
|
|
131
145
|
private initializedClusters;
|
|
132
146
|
/**
|
|
133
147
|
* Creates a clustered queue.
|
|
@@ -260,6 +274,11 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
|
|
|
260
274
|
* in-flight messages are not counted.
|
|
261
275
|
*/
|
|
262
276
|
queueLength(): Promise<number>;
|
|
277
|
+
/**
|
|
278
|
+
* Writes a diagnostic line, but only under {@link IMQOptions.verbose}.
|
|
279
|
+
*
|
|
280
|
+
* @param message - the line to write
|
|
281
|
+
*/
|
|
263
282
|
private verbose;
|
|
264
283
|
/**
|
|
265
284
|
* Writes an unconditional line through this cluster's logger, in the
|
|
@@ -537,9 +556,52 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
|
|
|
537
556
|
* sharing an address are removed together.
|
|
538
557
|
*/
|
|
539
558
|
protected removeServer(server: IServerInput): void;
|
|
559
|
+
/**
|
|
560
|
+
* Adds a server to the cluster, optionally bringing its queue up to the
|
|
561
|
+
* cluster's current state.
|
|
562
|
+
*
|
|
563
|
+
* @param server - the server to add
|
|
564
|
+
* @param initializeQueue - whether to replay `start`/`subscribe` onto the
|
|
565
|
+
* new queue. Passed `false` while the cluster is still being
|
|
566
|
+
* constructed, when there is no state to replay yet
|
|
567
|
+
* @returns the server as registered, which is the existing entry when one
|
|
568
|
+
* already matched
|
|
569
|
+
*/
|
|
540
570
|
private addServerWithQueueInitializing;
|
|
571
|
+
/**
|
|
572
|
+
* Every emitter a listener registered on this cluster must reach.
|
|
573
|
+
*
|
|
574
|
+
* @returns the per-host queues plus the template emitter
|
|
575
|
+
*
|
|
576
|
+
* @remarks
|
|
577
|
+
* The template emitter is included so that listeners registered now are
|
|
578
|
+
* also carried onto queues created later, as servers join.
|
|
579
|
+
*/
|
|
541
580
|
private eventEmitters;
|
|
581
|
+
/**
|
|
582
|
+
* Brings a newly created per-host queue up to the cluster's current state.
|
|
583
|
+
*
|
|
584
|
+
* @param imq - the queue to initialize
|
|
585
|
+
*
|
|
586
|
+
* @remarks
|
|
587
|
+
* Replays whatever {@link ClusteredRedisQueue.state} records, so a server
|
|
588
|
+
* that joins after the cluster started is started and subscribed too rather
|
|
589
|
+
* than sitting idle.
|
|
590
|
+
*/
|
|
542
591
|
private initializeQueue;
|
|
592
|
+
/**
|
|
593
|
+
* Finds an already-registered server matching the given one.
|
|
594
|
+
*
|
|
595
|
+
* @param server - the server to look for
|
|
596
|
+
* @returns the registered entry, or `undefined` when it is new
|
|
597
|
+
*/
|
|
543
598
|
private findServer;
|
|
599
|
+
/**
|
|
600
|
+
* Decides whether two server descriptions refer to the same server.
|
|
601
|
+
*
|
|
602
|
+
* @param source - one server description
|
|
603
|
+
* @param target - the other
|
|
604
|
+
* @returns whether they are the same server
|
|
605
|
+
*/
|
|
544
606
|
private static matchServers;
|
|
545
607
|
}
|
|
@@ -112,10 +112,24 @@ export class ClusteredRedisQueue {
|
|
|
112
112
|
* cluster servers
|
|
113
113
|
*/
|
|
114
114
|
clusterEmitter;
|
|
115
|
+
/**
|
|
116
|
+
* What has been done to this queue so far, so that a server joining later
|
|
117
|
+
* can be brought to the same point.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* Cluster membership changes at runtime, so a per-host queue may be created
|
|
121
|
+
* long after `start()` and `subscribe()` were called on the cluster. This
|
|
122
|
+
* records those calls; {@link ClusteredRedisQueue.initializeQueue} replays
|
|
123
|
+
* them onto each new queue.
|
|
124
|
+
*/
|
|
115
125
|
state = {
|
|
116
126
|
started: false,
|
|
117
127
|
subscription: null,
|
|
118
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Handles for the cluster managers this queue is registered with, kept so
|
|
131
|
+
* that {@link ClusteredRedisQueue.destroy} can deregister from each.
|
|
132
|
+
*/
|
|
119
133
|
initializedClusters = [];
|
|
120
134
|
/**
|
|
121
135
|
* Creates a clustered queue.
|
|
@@ -341,6 +355,11 @@ export class ClusteredRedisQueue {
|
|
|
341
355
|
const lengths = await Promise.all(promises);
|
|
342
356
|
return lengths.reduce((total, length) => total + length, 0);
|
|
343
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Writes a diagnostic line, but only under {@link IMQOptions.verbose}.
|
|
360
|
+
*
|
|
361
|
+
* @param message - the line to write
|
|
362
|
+
*/
|
|
344
363
|
verbose(message) {
|
|
345
364
|
if (this.options.verbose) {
|
|
346
365
|
this.logger.info(`[IMQ-CORE][ClusteredRedisQueue][${this.name}]: ${message}`);
|
|
@@ -743,6 +762,17 @@ export class ClusteredRedisQueue {
|
|
|
743
762
|
imq: imqToRemove,
|
|
744
763
|
});
|
|
745
764
|
}
|
|
765
|
+
/**
|
|
766
|
+
* Adds a server to the cluster, optionally bringing its queue up to the
|
|
767
|
+
* cluster's current state.
|
|
768
|
+
*
|
|
769
|
+
* @param server - the server to add
|
|
770
|
+
* @param initializeQueue - whether to replay `start`/`subscribe` onto the
|
|
771
|
+
* new queue. Passed `false` while the cluster is still being
|
|
772
|
+
* constructed, when there is no state to replay yet
|
|
773
|
+
* @returns the server as registered, which is the existing entry when one
|
|
774
|
+
* already matched
|
|
775
|
+
*/
|
|
746
776
|
addServerWithQueueInitializing(server, initializeQueue = true) {
|
|
747
777
|
const existingServer = this.findServer(server);
|
|
748
778
|
if (existingServer) {
|
|
@@ -753,6 +783,13 @@ export class ClusteredRedisQueue {
|
|
|
753
783
|
host: server.host,
|
|
754
784
|
port: server.port,
|
|
755
785
|
};
|
|
786
|
+
// carried through only when the entry actually states it: the entry is
|
|
787
|
+
// spread over the cluster-wide options below, and a key present but
|
|
788
|
+
// undefined would blank out the top-level value rather than fall back
|
|
789
|
+
// to it
|
|
790
|
+
if (server.tls !== undefined) {
|
|
791
|
+
newServer.tls = server.tls;
|
|
792
|
+
}
|
|
756
793
|
const opts = { ...this.mqOptions, ...newServer };
|
|
757
794
|
const imq = new RedisQueue(this.name, opts);
|
|
758
795
|
copyEventEmitter(this.templateEmitter, imq);
|
|
@@ -771,9 +808,28 @@ export class ClusteredRedisQueue {
|
|
|
771
808
|
this.imqLength = this.imqs.length;
|
|
772
809
|
return newServer;
|
|
773
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Every emitter a listener registered on this cluster must reach.
|
|
813
|
+
*
|
|
814
|
+
* @returns the per-host queues plus the template emitter
|
|
815
|
+
*
|
|
816
|
+
* @remarks
|
|
817
|
+
* The template emitter is included so that listeners registered now are
|
|
818
|
+
* also carried onto queues created later, as servers join.
|
|
819
|
+
*/
|
|
774
820
|
eventEmitters() {
|
|
775
821
|
return [...this.imqs, this.templateEmitter];
|
|
776
822
|
}
|
|
823
|
+
/**
|
|
824
|
+
* Brings a newly created per-host queue up to the cluster's current state.
|
|
825
|
+
*
|
|
826
|
+
* @param imq - the queue to initialize
|
|
827
|
+
*
|
|
828
|
+
* @remarks
|
|
829
|
+
* Replays whatever {@link ClusteredRedisQueue.state} records, so a server
|
|
830
|
+
* that joins after the cluster started is started and subscribed too rather
|
|
831
|
+
* than sitting idle.
|
|
832
|
+
*/
|
|
777
833
|
async initializeQueue(imq) {
|
|
778
834
|
this.verbose(`Initializing queue with state: ${JSON.stringify(this.state)}`);
|
|
779
835
|
// both failures are reported here, inside the function, and the
|
|
@@ -799,9 +855,22 @@ export class ClusteredRedisQueue {
|
|
|
799
855
|
}
|
|
800
856
|
}
|
|
801
857
|
}
|
|
858
|
+
/**
|
|
859
|
+
* Finds an already-registered server matching the given one.
|
|
860
|
+
*
|
|
861
|
+
* @param server - the server to look for
|
|
862
|
+
* @returns the registered entry, or `undefined` when it is new
|
|
863
|
+
*/
|
|
802
864
|
findServer(server) {
|
|
803
865
|
return this.servers.find(existing => ClusteredRedisQueue.matchServers(existing, server));
|
|
804
866
|
}
|
|
867
|
+
/**
|
|
868
|
+
* Decides whether two server descriptions refer to the same server.
|
|
869
|
+
*
|
|
870
|
+
* @param source - one server description
|
|
871
|
+
* @param target - the other
|
|
872
|
+
* @returns whether they are the same server
|
|
873
|
+
*/
|
|
805
874
|
static matchServers(source, target) {
|
|
806
875
|
const sameAddress = target.host === source.host && target.port === source.port;
|
|
807
876
|
if (!target.id && !source.id) {
|
package/src/IMessageQueue.d.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import { EventEmitter } from 'node:events';
|
|
25
|
+
import type { ConnectionOptions as TlsOptions } from 'node:tls';
|
|
25
26
|
import { IMQMode } from './IMQMode.js';
|
|
26
27
|
import { ClusterManager } from './ClusterManager.js';
|
|
27
28
|
export { EventEmitter } from 'node:events';
|
|
@@ -154,20 +155,25 @@ export interface IMessageQueueConnection extends IMessageQueueAuthConnection {
|
|
|
154
155
|
*/
|
|
155
156
|
id?: string;
|
|
156
157
|
/**
|
|
157
|
-
* Host name or IP address of the queue host.
|
|
158
|
+
* Host name or IP address of the queue host.
|
|
159
|
+
*
|
|
160
|
+
* @defaultValue "localhost"
|
|
158
161
|
*/
|
|
159
162
|
host: string;
|
|
160
163
|
/**
|
|
161
|
-
* TCP port of the queue host.
|
|
164
|
+
* TCP port of the queue host.
|
|
165
|
+
*
|
|
166
|
+
* @defaultValue 6379
|
|
162
167
|
*/
|
|
163
168
|
port: number;
|
|
164
169
|
}
|
|
165
170
|
/**
|
|
166
171
|
* Optional credentials for a queue host, forwarded to the Redis client as
|
|
167
|
-
* `username` and `password
|
|
172
|
+
* `username` and `password`, plus the transport security to reach it with.
|
|
168
173
|
*
|
|
169
|
-
* Supply both for a Redis ACL user, or just `password` for a
|
|
170
|
-
* server. Omit both to connect unauthenticated, which is the
|
|
174
|
+
* Supply both credentials for a Redis ACL user, or just `password` for a
|
|
175
|
+
* `requirepass`-only server. Omit both to connect unauthenticated, which is the
|
|
176
|
+
* default.
|
|
171
177
|
*/
|
|
172
178
|
export interface IMessageQueueAuthConnection {
|
|
173
179
|
/**
|
|
@@ -178,6 +184,37 @@ export interface IMessageQueueAuthConnection {
|
|
|
178
184
|
* Password for the queue host.
|
|
179
185
|
*/
|
|
180
186
|
password?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Encrypts this connection with TLS. `true` connects with Node's defaults,
|
|
189
|
+
* verifying the server against the system trust store; an object is handed
|
|
190
|
+
* to `tls.connect()` as given, so supply `ca` for a private certificate
|
|
191
|
+
* authority and `cert` with `key` for mutual TLS.
|
|
192
|
+
*
|
|
193
|
+
* Applies to every channel the queue opens — reader, writer, watcher and
|
|
194
|
+
* subscription alike — so enabling it here encrypts the whole bus. The
|
|
195
|
+
* broker must be listening for TLS (`tls-port`); a server that is not will
|
|
196
|
+
* refuse the handshake rather than fall back to plaintext.
|
|
197
|
+
*
|
|
198
|
+
* @defaultValue undefined
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* The certificate is verified against {@link IMessageQueueConnection.host}
|
|
202
|
+
* unless `servername` says otherwise. A host that is a bare IP address
|
|
203
|
+
* therefore needs a certificate carrying that address as an IP SAN — reach
|
|
204
|
+
* the broker by the name on its certificate, or set `servername` to it.
|
|
205
|
+
*
|
|
206
|
+
* The writer and watcher connections are shared per server within the
|
|
207
|
+
* process, and that sharing accounts for this option: queues reaching the
|
|
208
|
+
* same host and port under different TLS configurations get separate
|
|
209
|
+
* connections rather than silently inheriting whichever was opened first.
|
|
210
|
+
* Configurations that are equal by value still share.
|
|
211
|
+
*
|
|
212
|
+
* When omitted, the environment is consulted instead — see
|
|
213
|
+
* `IMQ_REDIS_TLS` and its companions in {@link envTls} — which lets a
|
|
214
|
+
* deployment turn encryption on without a code change. Passing `false`
|
|
215
|
+
* declines that fallback and forces a plaintext connection.
|
|
216
|
+
*/
|
|
217
|
+
tls?: boolean | TlsOptions;
|
|
181
218
|
}
|
|
182
219
|
/**
|
|
183
220
|
* Options accepted by every queue implementation.
|
|
@@ -196,8 +233,9 @@ export interface IMessageQueueAuthConnection {
|
|
|
196
233
|
*/
|
|
197
234
|
export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
198
235
|
/**
|
|
199
|
-
* Turns on/off the watcher's periodic removal of orphaned keys.
|
|
200
|
-
*
|
|
236
|
+
* Turns on/off the watcher's periodic removal of orphaned keys.
|
|
237
|
+
*
|
|
238
|
+
* @defaultValue false
|
|
201
239
|
*
|
|
202
240
|
* @remarks
|
|
203
241
|
* This is a destructive sweep. Only the instance holding the watcher lock
|
|
@@ -211,9 +249,11 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
211
249
|
cleanup: boolean;
|
|
212
250
|
/**
|
|
213
251
|
* Redis glob pattern, appended to the prefix as `<prefix>:<cleanupFilter>`,
|
|
214
|
-
* selecting which keys the cleanup sweep considers.
|
|
252
|
+
* selecting which keys the cleanup sweep considers. The default matches
|
|
215
253
|
* every key in the namespace.
|
|
216
254
|
*
|
|
255
|
+
* @defaultValue "*"
|
|
256
|
+
*
|
|
217
257
|
* @remarks
|
|
218
258
|
* This matches Redis key names, not queue names. The same pattern is also
|
|
219
259
|
* matched against connection names when deciding which keys belong to live
|
|
@@ -221,8 +261,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
221
261
|
*/
|
|
222
262
|
cleanupFilter: string;
|
|
223
263
|
/**
|
|
224
|
-
* Queue adapter vendor name
|
|
225
|
-
*
|
|
264
|
+
* Queue adapter vendor name, and the only supported value.
|
|
265
|
+
*
|
|
266
|
+
* @defaultValue "Redis"
|
|
226
267
|
*
|
|
227
268
|
* @remarks
|
|
228
269
|
* Honoured only by {@link IMQ.create}, which throws a `TypeError` for any
|
|
@@ -231,7 +272,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
231
272
|
*/
|
|
232
273
|
vendor?: string;
|
|
233
274
|
/**
|
|
234
|
-
* Global key namespace for everything this queue writes.
|
|
275
|
+
* Global key namespace for everything this queue writes.
|
|
276
|
+
*
|
|
277
|
+
* @defaultValue "imq"
|
|
235
278
|
*
|
|
236
279
|
* @remarks
|
|
237
280
|
* The prefix scopes more than the queue keys: it also scopes the delayed set,
|
|
@@ -243,7 +286,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
243
286
|
*/
|
|
244
287
|
prefix?: string;
|
|
245
288
|
/**
|
|
246
|
-
* Logger used for queue diagnostics.
|
|
289
|
+
* Logger used for queue diagnostics.
|
|
290
|
+
*
|
|
291
|
+
* @defaultValue console
|
|
247
292
|
*
|
|
248
293
|
* @remarks
|
|
249
294
|
* Connection lifecycle messages and all internal errors are written here
|
|
@@ -252,7 +297,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
252
297
|
*/
|
|
253
298
|
logger?: ILogger;
|
|
254
299
|
/**
|
|
255
|
-
* Interval in milliseconds of the periodic watcher check.
|
|
300
|
+
* Interval in milliseconds of the periodic watcher check.
|
|
301
|
+
*
|
|
302
|
+
* @defaultValue 5000
|
|
256
303
|
*
|
|
257
304
|
* @remarks
|
|
258
305
|
* Each tick re-elects a watcher owner if none exists and, on
|
|
@@ -260,6 +307,14 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
260
307
|
* fallback when Redis keyspace notifications are unavailable. That makes this
|
|
261
308
|
* value the worst-case extra latency for a delayed message. Setting it to `0`
|
|
262
309
|
* disables both behaviours.
|
|
310
|
+
*
|
|
311
|
+
* It also paces the watcher's maintenance sweep, which recovers the
|
|
312
|
+
* messages of workers that have died and drives the
|
|
313
|
+
* {@link IMQOptions.cleanup} pass — so this, not
|
|
314
|
+
* {@link IMQOptions.safeDeliveryTtl}, is the worst-case latency for a
|
|
315
|
+
* crashed worker's message coming back. With the check disabled the sweep
|
|
316
|
+
* falls back to `safeDeliveryTtl`, which on a large budget is very slow;
|
|
317
|
+
* leave it on if safe delivery matters.
|
|
263
318
|
*/
|
|
264
319
|
watcherCheckDelay?: number;
|
|
265
320
|
/**
|
|
@@ -271,8 +326,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
271
326
|
* Must be set identically on every producer and consumer of a queue: a
|
|
272
327
|
* mismatch makes deserialization fail, which emits an `error` event with the
|
|
273
328
|
* event name `OnMessage` and drops the message — permanently, even under
|
|
274
|
-
* {@link IMQOptions.safeDelivery}
|
|
275
|
-
*
|
|
329
|
+
* {@link IMQOptions.safeDelivery}: a message that cannot be unpacked reaches
|
|
330
|
+
* no listener, so nothing is pending on it and its lease is released at
|
|
331
|
+
* once. Re-delivering it would only fail the same way.
|
|
276
332
|
*
|
|
277
333
|
* Applies to queue messages only. {@link IMessageQueue.publish} and
|
|
278
334
|
* {@link IMessageQueue.subscribe} payloads are always plain JSON.
|
|
@@ -285,42 +341,58 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
285
341
|
* message leaves that message behind for the watcher to re-queue rather
|
|
286
342
|
* than taking it down with the process.
|
|
287
343
|
*
|
|
288
|
-
* The guarantee covers
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
344
|
+
* The guarantee covers the processing too, not only the hand-off: the
|
|
345
|
+
* worker key is held until the `message` listener has finished with the
|
|
346
|
+
* message, which for a listener returning a promise means until that
|
|
347
|
+
* promise settles. A worker killed at any point before then leaves the
|
|
348
|
+
* message behind to be re-queued.
|
|
349
|
+
*
|
|
350
|
+
* A message comes back on either of two counts. The owning process leaving
|
|
351
|
+
* the broker's client list catches it dying — a fact the broker holds
|
|
352
|
+
* rather than an inference from a clock, so it is noticed as fast as the
|
|
353
|
+
* socket closes and nothing has to be renewed to keep a live lease alive.
|
|
354
|
+
* {@link IMQOptions.safeDeliveryTtl} catches what liveness cannot see: one
|
|
355
|
+
* handler wedged inside a worker that is otherwise up and serving.
|
|
356
|
+
*
|
|
357
|
+
* Delivery is at-least-once in either mode, so handlers should be
|
|
358
|
+
* idempotent: this narrows the window in which in-flight work is lost, it
|
|
359
|
+
* does not close it.
|
|
294
360
|
*
|
|
295
361
|
* @defaultValue false
|
|
296
362
|
*/
|
|
297
363
|
safeDelivery?: boolean;
|
|
298
364
|
/**
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* the watcher sweeps for expired keys. A worker key still present once its
|
|
302
|
-
* deadline has passed is treated as abandoned, and its message is moved
|
|
303
|
-
* back onto the main queue.
|
|
365
|
+
* The longest (in milliseconds) a message may be worked on before it is
|
|
366
|
+
* treated as abandoned and moved back onto the queue.
|
|
304
367
|
*
|
|
305
|
-
*
|
|
306
|
-
* deadline. The key is released when the message is dispatched, so a slow
|
|
307
|
-
* handler is neither interrupted nor re-queued for taking too long, and
|
|
308
|
-
* raising this value extends no protection over long-running work — tune it
|
|
309
|
-
* for how quickly an abandoned message should come back.
|
|
310
|
-
*
|
|
311
|
-
* @defaultValue 5000
|
|
368
|
+
* @defaultValue 300000
|
|
312
369
|
*
|
|
313
370
|
* @remarks
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
371
|
+
* Set it to the longest a handler in this system can legitimately take,
|
|
372
|
+
* with headroom. A slow upstream is the usual reason for a large value — a
|
|
373
|
+
* data vendor with no job API, screen-scraping behind an HTTP call,
|
|
374
|
+
* anything that can take minutes — and a budget below that reclaims a
|
|
375
|
+
* message from a worker still legitimately working on it, handing somebody
|
|
376
|
+
* else a duplicate.
|
|
377
|
+
*
|
|
378
|
+
* This is the **only** thing that recovers a message from a worker that is
|
|
379
|
+
* alive, connected and serving other messages while one handler has wedged
|
|
380
|
+
* on this one. Death of the whole process is caught separately and far
|
|
381
|
+
* faster, by the owner leaving the broker's client list, so this value does
|
|
382
|
+
* not govern how quickly an ordinary crash is recovered from.
|
|
383
|
+
*
|
|
384
|
+
* Two internals follow this value but deliberately do not scale with it:
|
|
385
|
+
*
|
|
386
|
+
* - The watcher's maintenance sweep — which recovers abandoned leases and
|
|
387
|
+
* drives the {@link IMQOptions.cleanup} pass — runs on
|
|
388
|
+
* {@link IMQOptions.watcherCheckDelay}, so a dead worker is still noticed
|
|
389
|
+
* within seconds however generous the budget is. Setting this to `null`
|
|
390
|
+
* or `undefined` disables that sweep altogether, so neither lease
|
|
391
|
+
* recovery nor cleanup runs.
|
|
392
|
+
* - The reader's blocking pop is half this value capped at 5000 ms, with a
|
|
393
|
+
* 100 ms floor. The cap matters: a lease deadline is stamped before the
|
|
394
|
+
* pop that fills the key, so an uncapped wait would hand a message a
|
|
395
|
+
* sizeable part of its budget already spent.
|
|
324
396
|
*/
|
|
325
397
|
safeDeliveryTtl?: number;
|
|
326
398
|
/**
|
|
@@ -333,8 +405,12 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
|
|
|
333
405
|
* cluster-membership matching. Sends are distributed across the servers by
|
|
334
406
|
* health-aware round-robin, preferring ones whose connection is ready.
|
|
335
407
|
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
408
|
+
* An entry may carry its own `tls`, overriding the top-level one for that
|
|
409
|
+
* server alone — for a cluster whose members do not share trust anchors.
|
|
410
|
+
* An entry that leaves it out falls back to the top level.
|
|
411
|
+
*
|
|
412
|
+
* Per-entry `username` and `password` remain ignored: the underlying
|
|
413
|
+
* queues authenticate with the top-level credentials.
|
|
338
414
|
*/
|
|
339
415
|
cluster?: IMessageQueueConnection[];
|
|
340
416
|
/**
|
|
@@ -397,6 +473,20 @@ export interface EventMap {
|
|
|
397
473
|
/**
|
|
398
474
|
* Emitted for every message consumed from the queue, with the payload, the
|
|
399
475
|
* message id, and the name of the queue that sent it.
|
|
476
|
+
*
|
|
477
|
+
* @remarks
|
|
478
|
+
* Under {@link IMQOptions.safeDelivery} the value a listener **returns**
|
|
479
|
+
* decides when the message counts as handled. Return a promise and the
|
|
480
|
+
* message stays checked out until it settles, so a worker that dies
|
|
481
|
+
* mid-handler leaves it behind to be re-queued. Return anything else and it
|
|
482
|
+
* is released as the listener returns, which is all a synchronous handler
|
|
483
|
+
* can offer — and is also how to opt out, by starting the work and
|
|
484
|
+
* returning nothing.
|
|
485
|
+
*
|
|
486
|
+
* Every registered listener is consulted, and the message is released once
|
|
487
|
+
* all the promises they returned have settled — settled, not fulfilled: a
|
|
488
|
+
* handler that throws has still had its turn, and re-delivering on a
|
|
489
|
+
* rejection would retry a poison message forever.
|
|
400
490
|
*/
|
|
401
491
|
message: [data: JsonObject, id: string, from: string];
|
|
402
492
|
/**
|
|
@@ -636,9 +726,11 @@ export interface IMessageQueue extends EventEmitter<EventMap> {
|
|
|
636
726
|
*
|
|
637
727
|
* @remarks
|
|
638
728
|
* Other queues in the namespace, the watcher lock, and messages currently
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* this does not guarantee
|
|
729
|
+
* checked out to a worker under {@link IMQOptions.safeDelivery} are all
|
|
730
|
+
* untouched — such a message returns to the queue if its worker dies or
|
|
731
|
+
* overruns {@link IMQOptions.safeDeliveryTtl}, so this does not guarantee
|
|
732
|
+
* the queue stays empty. A message is checked out for as long as its
|
|
733
|
+
* handler runs, so that window is as long as your slowest handler.
|
|
642
734
|
*
|
|
643
735
|
* It never rejects: with no writer connection it silently does nothing, and
|
|
644
736
|
* host failures are logged rather than raised, so success cannot be inferred
|
|
@@ -651,9 +743,11 @@ export interface IMessageQueue extends EventEmitter<EventMap> {
|
|
|
651
743
|
* @returns count of messages waiting to be consumed
|
|
652
744
|
*
|
|
653
745
|
* @remarks
|
|
654
|
-
* Delayed messages that are not yet due, and messages currently
|
|
655
|
-
* worker under {@link IMQOptions.safeDelivery}, are not counted — so
|
|
656
|
-
* is not the amount of outstanding work.
|
|
746
|
+
* Delayed messages that are not yet due, and messages currently checked out
|
|
747
|
+
* to a worker under {@link IMQOptions.safeDelivery}, are not counted — so
|
|
748
|
+
* this is not the amount of outstanding work. Under safe delivery a message
|
|
749
|
+
* is checked out for as long as its handler runs, so on a busy queue the
|
|
750
|
+
* shortfall is roughly everything in flight, not a rounding error.
|
|
657
751
|
*
|
|
658
752
|
* Returns `0` when the queue has no writer connection, which makes
|
|
659
753
|
* "disconnected" indistinguishable from "empty".
|