redis-smq 8.0.0-rc.12 → 8.0.0-rc.14
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/CHANGELOG.md +43 -0
- package/README.md +2 -2
- package/dist/index.cjs +58 -52
- package/dist/index.d.cts +61 -74
- package/dist/index.d.ts +61 -74
- package/dist/index.js +58 -52
- package/dist/lua/delete-message.lua +34 -29
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [8.0.0-rc.14](https://github.com/weyoss/redis-smq/compare/v8.0.0-rc.13...v8.0.0-rc.14) (2024-01-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Documentation
|
|
7
|
+
|
|
8
|
+
* add new diagrams and update existing ones ([f5182b1](https://github.com/weyoss/redis-smq/commit/f5182b10b5179365edf68e7b6bf564ccc25281ab))
|
|
9
|
+
* **event-listeners:** add a link to IRedisSMQConfig interface ([a7635c5](https://github.com/weyoss/redis-smq/commit/a7635c5d811ad775123547a5696c78b030981269))
|
|
10
|
+
* scale down diagrams ([c3b37e4](https://github.com/weyoss/redis-smq/commit/c3b37e445a6d15fdcc8c7a73b713a1f7d5e7c94e))
|
|
11
|
+
* update exchange diagrams ([9dc05d6](https://github.com/weyoss/redis-smq/commit/9dc05d6cd835d779b9d183e83f562c7991105c92))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Codebase Refactoring
|
|
15
|
+
|
|
16
|
+
* **event-listeners:** clean up ([d9195e4](https://github.com/weyoss/redis-smq/commit/d9195e4e85e2e4519d238f5f3ecace37ae9bbb32))
|
|
17
|
+
* **exchanges:** improve typings ([97665fe](https://github.com/weyoss/redis-smq/commit/97665fed4a579af444c46e01a6b05f9adb12e888))
|
|
18
|
+
* **message:** handle various errors when deleting a message ([a4505ae](https://github.com/weyoss/redis-smq/commit/a4505ae7d95bda0185da28433c6737e395400e7b))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
* **message:** handle various errors when deleting a message ([ecf301b](https://github.com/weyoss/redis-smq/commit/ecf301b06aac1bf6d0fcb1ced962a32ac6a6ca68))
|
|
24
|
+
|
|
25
|
+
## [8.0.0-rc.13](https://github.com/weyoss/redis-smq/compare/v8.0.0-rc.12...v8.0.0-rc.13) (2023-12-23)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### ⚠ BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* **event-listeners:** unify consumer/producer event listeners
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
|
|
34
|
+
* **event-listeners:** update documentation ([71100d3](https://github.com/weyoss/redis-smq/commit/71100d3aa94a61fb8ece86e439f0b120b66a6cab))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Codebase Refactoring
|
|
38
|
+
|
|
39
|
+
* **event-listeners:** unify consumer/producer event listeners ([9e1a181](https://github.com/weyoss/redis-smq/commit/9e1a1811dd841d4329f0ee14e979d2770a7a6358))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Tests
|
|
43
|
+
|
|
44
|
+
* **event-listeners:** unify consumer/producer event listeners ([2d14a07](https://github.com/weyoss/redis-smq/commit/2d14a077feda98933fb6c038bea5a33ad8d5f610))
|
|
45
|
+
|
|
3
46
|
## [8.0.0-rc.12](https://github.com/weyoss/redis-smq/compare/v8.0.0-rc.11...v8.0.0-rc.12) (2023-12-18)
|
|
4
47
|
|
|
5
48
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center" style="text-align: center">
|
|
2
2
|
<p><a href="https://github.com/weyoss/redis-smq"><img alt="RedisSMQ" src="./logo.png?v=202312182134" /></a></p>
|
|
3
|
-
<p>A simple high-performance Redis message queue for Node.js.</p>
|
|
3
|
+
<p style='color: #d82c20'>A simple high-performance Redis message queue for Node.js.</p>
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
# RedisSMQ
|
|
@@ -35,7 +35,7 @@ RedisSMQ is a Node.js library for queuing messages (aka jobs) and processing the
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-

|
|
39
39
|
|
|
40
40
|
## What's new?
|
|
41
41
|
|
package/dist/index.cjs
CHANGED
|
@@ -339,14 +339,10 @@ function Messages(userConfig) {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
// src/config/event-listeners/event-listeners.ts
|
|
342
|
-
var
|
|
343
|
-
var defaultConfig4 = {
|
|
344
|
-
consumerEventListeners: [],
|
|
345
|
-
producerEventListeners: []
|
|
346
|
-
};
|
|
342
|
+
var defaultConfig4 = [];
|
|
347
343
|
function EventListeners(userConfig) {
|
|
348
|
-
const { eventListeners =
|
|
349
|
-
return
|
|
344
|
+
const { eventListeners = [] } = userConfig;
|
|
345
|
+
return [...defaultConfig4, ...eventListeners];
|
|
350
346
|
}
|
|
351
347
|
|
|
352
348
|
// src/config/configuration.ts
|
|
@@ -408,11 +404,11 @@ function _destroyCommonRedisClient(cb) {
|
|
|
408
404
|
}
|
|
409
405
|
|
|
410
406
|
// types/consumer/consume-message.ts
|
|
411
|
-
var EConsumeMessageDeadLetterCause = /* @__PURE__ */ ((
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return
|
|
407
|
+
var EConsumeMessageDeadLetterCause = /* @__PURE__ */ ((EConsumeMessageDeadLetterCause2) => {
|
|
408
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["TTL_EXPIRED"] = 0] = "TTL_EXPIRED";
|
|
409
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["RETRY_THRESHOLD_EXCEEDED"] = 1] = "RETRY_THRESHOLD_EXCEEDED";
|
|
410
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["PERIODIC_MESSAGE"] = 2] = "PERIODIC_MESSAGE";
|
|
411
|
+
return EConsumeMessageDeadLetterCause2;
|
|
416
412
|
})(EConsumeMessageDeadLetterCause || {});
|
|
417
413
|
var EConsumeMessageUnacknowledgedCause = /* @__PURE__ */ ((EConsumeMessageUnacknowledgedCause3) => {
|
|
418
414
|
EConsumeMessageUnacknowledgedCause3[EConsumeMessageUnacknowledgedCause3["TIMEOUT"] = 0] = "TIMEOUT";
|
|
@@ -424,7 +420,7 @@ var EConsumeMessageUnacknowledgedCause = /* @__PURE__ */ ((EConsumeMessageUnackn
|
|
|
424
420
|
return EConsumeMessageUnacknowledgedCause3;
|
|
425
421
|
})(EConsumeMessageUnacknowledgedCause || {});
|
|
426
422
|
|
|
427
|
-
// types/exchange/
|
|
423
|
+
// types/exchange/common.ts
|
|
428
424
|
var EExchangeType = /* @__PURE__ */ ((EExchangeType2) => {
|
|
429
425
|
EExchangeType2[EExchangeType2["DIRECT"] = 0] = "DIRECT";
|
|
430
426
|
EExchangeType2[EExchangeType2["FANOUT"] = 1] = "FANOUT";
|
|
@@ -788,6 +784,10 @@ var Base = class extends import_redis_smq_common11.EventEmitter {
|
|
|
788
784
|
} else
|
|
789
785
|
cb();
|
|
790
786
|
};
|
|
787
|
+
this.initEventListeners = (cb) => {
|
|
788
|
+
const { eventListeners } = Configuration.getSetConfig();
|
|
789
|
+
this.registerEventListeners(eventListeners, cb);
|
|
790
|
+
};
|
|
791
791
|
this.tearDownEventListeners = (cb) => {
|
|
792
792
|
import_redis_smq_common11.async.each(
|
|
793
793
|
this.eventListeners,
|
|
@@ -818,7 +818,7 @@ var Base = class extends import_redis_smq_common11.EventEmitter {
|
|
|
818
818
|
this.on("error", (err) => this.handleError(err));
|
|
819
819
|
}
|
|
820
820
|
goingUp() {
|
|
821
|
-
return [this.setUpSharedRedisClient];
|
|
821
|
+
return [this.setUpSharedRedisClient, this.initEventListeners];
|
|
822
822
|
}
|
|
823
823
|
up(cb) {
|
|
824
824
|
this.powerSwitch.commit();
|
|
@@ -843,24 +843,21 @@ var Base = class extends import_redis_smq_common11.EventEmitter {
|
|
|
843
843
|
Ctors,
|
|
844
844
|
(ctor, key, done) => {
|
|
845
845
|
const instance = new ctor();
|
|
846
|
-
instance.init(
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
if (err)
|
|
853
|
-
done(err);
|
|
854
|
-
else {
|
|
855
|
-
this.eventListeners.push(instance);
|
|
856
|
-
done();
|
|
857
|
-
}
|
|
846
|
+
instance.init((err) => {
|
|
847
|
+
if (err)
|
|
848
|
+
done(err);
|
|
849
|
+
else {
|
|
850
|
+
this.eventListeners.push(instance);
|
|
851
|
+
done();
|
|
858
852
|
}
|
|
859
|
-
);
|
|
853
|
+
});
|
|
860
854
|
},
|
|
861
855
|
cb
|
|
862
856
|
);
|
|
863
857
|
}
|
|
858
|
+
hasEventListeners() {
|
|
859
|
+
return !!Configuration.getSetConfig().eventListeners.length;
|
|
860
|
+
}
|
|
864
861
|
handleError(err) {
|
|
865
862
|
if (this.powerSwitch.isGoingUp() || this.powerSwitch.isRunning()) {
|
|
866
863
|
throw err;
|
|
@@ -2931,20 +2928,20 @@ var ConsumeMessage = class {
|
|
|
2931
2928
|
const consumerId = this.messageHandler.getConsumerId();
|
|
2932
2929
|
this.messageHandler.emit(
|
|
2933
2930
|
"messageUnacknowledged",
|
|
2934
|
-
cause,
|
|
2935
2931
|
messageId,
|
|
2936
2932
|
queue,
|
|
2937
2933
|
messageHandlerId,
|
|
2938
|
-
consumerId
|
|
2934
|
+
consumerId,
|
|
2935
|
+
cause
|
|
2939
2936
|
);
|
|
2940
2937
|
if (reply.action === 0 /* DEAD_LETTER */) {
|
|
2941
2938
|
this.messageHandler.emit(
|
|
2942
2939
|
"messageDeadLettered",
|
|
2943
|
-
reply.deadLetterCause,
|
|
2944
2940
|
messageId,
|
|
2945
2941
|
queue,
|
|
2946
2942
|
messageHandlerId,
|
|
2947
|
-
consumerId
|
|
2943
|
+
consumerId,
|
|
2944
|
+
reply.deadLetterCause
|
|
2948
2945
|
);
|
|
2949
2946
|
} else if (reply.action === 2 /* DELAY */) {
|
|
2950
2947
|
this.messageHandler.emit(
|
|
@@ -3065,7 +3062,7 @@ var MessageHandler = class extends import_redis_smq_common27.EventEmitter {
|
|
|
3065
3062
|
});
|
|
3066
3063
|
this.on(
|
|
3067
3064
|
"messageDeadLettered",
|
|
3068
|
-
(
|
|
3065
|
+
(messageId, queue, messageHandlerId, consumerId, cause) => {
|
|
3069
3066
|
this.logger.info(
|
|
3070
3067
|
`Message (ID ${messageId}) dead-lettered (cause ${cause})`
|
|
3071
3068
|
);
|
|
@@ -3073,7 +3070,7 @@ var MessageHandler = class extends import_redis_smq_common27.EventEmitter {
|
|
|
3073
3070
|
);
|
|
3074
3071
|
this.on(
|
|
3075
3072
|
"messageUnacknowledged",
|
|
3076
|
-
(
|
|
3073
|
+
(messageId, queue, messageHandlerId, consumerId, cause) => {
|
|
3077
3074
|
this.logger.info(
|
|
3078
3075
|
`Message (ID ${messageId}) unacknowledged (cause ${cause})`
|
|
3079
3076
|
);
|
|
@@ -3940,12 +3937,6 @@ var Consumer = class extends Base {
|
|
|
3940
3937
|
this.workerRunner.addWorker(new publish_scheduled_worker_default(redisClient2, true));
|
|
3941
3938
|
this.workerRunner.run();
|
|
3942
3939
|
};
|
|
3943
|
-
this.initConsumerEventListeners = (cb) => {
|
|
3944
|
-
this.registerEventListeners(
|
|
3945
|
-
Configuration.getSetConfig().eventListeners.consumerEventListeners,
|
|
3946
|
-
cb
|
|
3947
|
-
);
|
|
3948
|
-
};
|
|
3949
3940
|
this.tearDownConsumerWorkers = (cb) => {
|
|
3950
3941
|
if (this.workerRunner) {
|
|
3951
3942
|
this.workerRunner.quit(() => {
|
|
@@ -3972,10 +3963,29 @@ var Consumer = class extends Base {
|
|
|
3972
3963
|
this.messageHandlerRunner = useMultiplexing ? new MultiplexedMessageHandlerRunner(this, nsLogger) : new MessageHandlerRunner(this, nsLogger);
|
|
3973
3964
|
this.redisKeys = redisKeys.getConsumerKeys(this.getId());
|
|
3974
3965
|
}
|
|
3966
|
+
registerSystemEventListeners() {
|
|
3967
|
+
super.registerSystemEventListeners();
|
|
3968
|
+
if (this.hasEventListeners()) {
|
|
3969
|
+
this.on("messageAcknowledged", (...args) => {
|
|
3970
|
+
this.eventListeners.forEach(
|
|
3971
|
+
(i) => i.emit("messageAcknowledged", ...args)
|
|
3972
|
+
);
|
|
3973
|
+
});
|
|
3974
|
+
this.on("messageUnacknowledged", (...args) => {
|
|
3975
|
+
this.eventListeners.forEach(
|
|
3976
|
+
(i) => i.emit("messageUnacknowledged", ...args)
|
|
3977
|
+
);
|
|
3978
|
+
});
|
|
3979
|
+
this.on("messageDeadLettered", (...args) => {
|
|
3980
|
+
this.eventListeners.forEach(
|
|
3981
|
+
(i) => i.emit("messageDeadLettered", ...args)
|
|
3982
|
+
);
|
|
3983
|
+
});
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3975
3986
|
goingUp() {
|
|
3976
3987
|
return super.goingUp().concat([
|
|
3977
3988
|
this.setUpHeartbeat,
|
|
3978
|
-
this.initConsumerEventListeners,
|
|
3979
3989
|
this.runMessageHandlers,
|
|
3980
3990
|
this.setUpConsumerWorkers
|
|
3981
3991
|
]);
|
|
@@ -4061,17 +4071,13 @@ function _scheduleMessage(mixed, message, cb) {
|
|
|
4061
4071
|
|
|
4062
4072
|
// src/lib/producer/producer.ts
|
|
4063
4073
|
var Producer = class extends Base {
|
|
4064
|
-
|
|
4065
|
-
super(
|
|
4066
|
-
this.
|
|
4067
|
-
this.
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
};
|
|
4072
|
-
}
|
|
4073
|
-
goingUp() {
|
|
4074
|
-
return super.goingUp().concat([this.initProducerEventListeners]);
|
|
4074
|
+
registerSystemEventListeners() {
|
|
4075
|
+
super.registerSystemEventListeners();
|
|
4076
|
+
if (this.hasEventListeners()) {
|
|
4077
|
+
this.on("messagePublished", (...args) => {
|
|
4078
|
+
this.eventListeners.forEach((i) => i.emit("messagePublished", ...args));
|
|
4079
|
+
});
|
|
4080
|
+
}
|
|
4075
4081
|
}
|
|
4076
4082
|
enqueue(redisClient2, queue, message, cb) {
|
|
4077
4083
|
var _a;
|
|
@@ -4141,7 +4147,7 @@ var Producer = class extends Base {
|
|
|
4141
4147
|
cb(err);
|
|
4142
4148
|
else {
|
|
4143
4149
|
this.logger.info(`Message (ID ${messageId}) has been published.`);
|
|
4144
|
-
this.emit("messagePublished", messageId, queue);
|
|
4150
|
+
this.emit("messagePublished", messageId, queue, this.id);
|
|
4145
4151
|
cb(null, messageId);
|
|
4146
4152
|
}
|
|
4147
4153
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -387,60 +387,84 @@ declare enum EConsumeMessageUnacknowledgedCause {
|
|
|
387
387
|
|
|
388
388
|
type TRedisSMQEvent = TEvent & {
|
|
389
389
|
heartbeatTick: (timestamp: number, consumerId: string, heartbeatPayload: IConsumerHeartbeat) => void;
|
|
390
|
-
messagePublished: (messageId: string, queue: IQueueParams) => void;
|
|
390
|
+
messagePublished: (messageId: string, queue: IQueueParams, producerId: string) => void;
|
|
391
391
|
messageAcknowledged: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
392
|
-
messageUnacknowledged: (
|
|
393
|
-
messageDeadLettered: (
|
|
392
|
+
messageUnacknowledged: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string, cause: EConsumeMessageUnacknowledgedCause) => void;
|
|
393
|
+
messageDeadLettered: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string, cause: EConsumeMessageDeadLetterCause) => void;
|
|
394
394
|
messageReceived: (messageId: string, queue: IQueueParams, consumerId: string) => void;
|
|
395
395
|
messageRequeued: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
396
396
|
messageDelayed: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
397
397
|
};
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
instanceId: string;
|
|
402
|
-
};
|
|
403
|
-
interface IEventListener {
|
|
404
|
-
init(args: TEventListenerInitArgs, cb: ICallback<void>): void;
|
|
399
|
+
interface IEventListener extends EventEmitter<TRedisSMQEvent> {
|
|
400
|
+
init(cb: ICallback<void>): void;
|
|
405
401
|
quit(cb: ICallback<void>): void;
|
|
406
402
|
}
|
|
407
403
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
404
|
+
type TEventListenersConfig = (new () => IEventListener)[];
|
|
405
|
+
|
|
406
|
+
declare abstract class Exchange<TBindingParams, ExchangeType extends EExchangeType> implements IExchange<TBindingParams, ExchangeType> {
|
|
407
|
+
readonly type: ExchangeType;
|
|
408
|
+
readonly bindingParams: TBindingParams;
|
|
409
|
+
exchangeTag: string;
|
|
410
|
+
protected constructor(bindingParams: TBindingParams, type: ExchangeType);
|
|
411
|
+
protected generateExchangeTag(): string;
|
|
412
|
+
getBindingParams(): TBindingParams;
|
|
413
|
+
toJSON(): IExchangeSerialized<TBindingParams, ExchangeType>;
|
|
414
|
+
fromJSON(JSON: Partial<IExchangeSerialized<TBindingParams, ExchangeType>>): void;
|
|
415
|
+
protected abstract validateBindingParams(bindingParams: TBindingParams): TBindingParams;
|
|
416
|
+
abstract getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
declare class ExchangeDirect extends Exchange<TExchangeDirectBindingParams, EExchangeType.DIRECT> {
|
|
420
|
+
constructor(queue: TExchangeDirectBindingParams);
|
|
421
|
+
protected validateBindingParams(queue: TExchangeDirectBindingParams): IQueueParams;
|
|
422
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
declare class ExchangeTopic extends Exchange<TExchangeTopicBindingParams, EExchangeType.TOPIC> {
|
|
426
|
+
constructor(topic: TExchangeTopicBindingParams);
|
|
427
|
+
protected validateBindingParams(topicParams: TExchangeTopicBindingParams): TTopicParams;
|
|
428
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
declare class ExchangeFanOut extends Exchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT> {
|
|
432
|
+
constructor(fanOutName: TExchangeFanOutBindingParams);
|
|
433
|
+
protected validateBindingParams(bindingParams: TExchangeFanOutBindingParams): string;
|
|
434
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
435
|
+
saveExchange(cb: ICallback<void>): void;
|
|
436
|
+
deleteExchange(cb: ICallback<void>): void;
|
|
437
|
+
bindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
438
|
+
unbindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
439
|
+
static getAllExchanges(cb: ICallback<string[]>): void;
|
|
440
|
+
static getQueueExchange(queue: IQueueParams | string, cb: ICallback<ExchangeFanOut | null>): void;
|
|
411
441
|
}
|
|
412
|
-
type IEventListenersConfigRequired = Required<IEventListenersConfig>;
|
|
413
442
|
|
|
414
|
-
type TTopicParams = {
|
|
415
|
-
topic: string;
|
|
416
|
-
ns: string;
|
|
417
|
-
};
|
|
418
443
|
declare enum EExchangeType {
|
|
419
444
|
DIRECT = 0,
|
|
420
445
|
FANOUT = 1,
|
|
421
446
|
TOPIC = 2
|
|
422
447
|
}
|
|
448
|
+
type TTopicParams = {
|
|
449
|
+
topic: string;
|
|
450
|
+
ns: string;
|
|
451
|
+
};
|
|
423
452
|
type TExchangeDirectBindingParams = IQueueParams | string;
|
|
424
|
-
type TExchangeFanOutBindingParams = string;
|
|
425
453
|
type TExchangeTopicBindingParams = TTopicParams | string;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
454
|
+
type TExchangeFanOutBindingParams = string;
|
|
455
|
+
type TExchange = ExchangeDirect | ExchangeTopic | ExchangeFanOut;
|
|
456
|
+
type TExchangeSerialized = ReturnType<ExchangeDirect['toJSON']> | ReturnType<ExchangeTopic['toJSON']> | ReturnType<ExchangeFanOut['toJSON']>;
|
|
457
|
+
|
|
431
458
|
interface IExchangeSerialized<BindingParams, ExchangeType extends EExchangeType> {
|
|
432
459
|
readonly type: ExchangeType;
|
|
433
460
|
readonly bindingParams: BindingParams;
|
|
434
461
|
readonly exchangeTag: string;
|
|
435
462
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
type TExchangeFanOut = IExchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT>;
|
|
442
|
-
type TExchange = TExchangeDirect | TExchangeTopic | TExchangeFanOut;
|
|
443
|
-
type TExchangeSerialized = TExchangeDirectSerialized | TExchangeTopicSerialized | TExchangeFanOutSerialized;
|
|
463
|
+
interface IExchange<BindingParams, ExchangeType extends EExchangeType> extends IExchangeSerialized<BindingParams, ExchangeType> {
|
|
464
|
+
toJSON(): IExchangeSerialized<BindingParams, ExchangeType>;
|
|
465
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
466
|
+
getBindingParams(): BindingParams;
|
|
467
|
+
}
|
|
444
468
|
|
|
445
469
|
interface IQueueMessages {
|
|
446
470
|
countMessages(queue: string | IQueueParams, cb: ICallback<number>): void;
|
|
@@ -470,13 +494,12 @@ interface IRedisSMQConfig {
|
|
|
470
494
|
namespace?: string;
|
|
471
495
|
logger?: ILoggerConfig;
|
|
472
496
|
messages?: IMessagesConfig;
|
|
473
|
-
eventListeners?:
|
|
497
|
+
eventListeners?: TEventListenersConfig;
|
|
474
498
|
}
|
|
475
499
|
interface IRedisSMQConfigRequired extends Required<IRedisSMQConfig> {
|
|
476
500
|
messages: {
|
|
477
501
|
store: IMessagesConfigStorageRequired;
|
|
478
502
|
};
|
|
479
|
-
eventListeners: IEventListenersConfigRequired;
|
|
480
503
|
}
|
|
481
504
|
|
|
482
505
|
declare class ConsumerError extends RedisSMQError {
|
|
@@ -587,6 +610,7 @@ declare abstract class Base extends EventEmitter<TRedisSMQEvent> {
|
|
|
587
610
|
constructor();
|
|
588
611
|
protected setUpSharedRedisClient: (cb: ICallback<void>) => void;
|
|
589
612
|
protected tearDownSharedRedisClient: (cb: ICallback<void>) => void;
|
|
613
|
+
protected initEventListeners: (cb: ICallback<void>) => void;
|
|
590
614
|
protected registerSystemEventListeners(): void;
|
|
591
615
|
protected goingUp(): TFunction[];
|
|
592
616
|
protected up(cb?: ICallback<boolean>): void;
|
|
@@ -595,6 +619,7 @@ declare abstract class Base extends EventEmitter<TRedisSMQEvent> {
|
|
|
595
619
|
protected getSharedRedisClient(): RedisClient;
|
|
596
620
|
protected registerEventListeners(Ctors: (new () => IEventListener)[], cb: ICallback<void>): void;
|
|
597
621
|
protected tearDownEventListeners: (cb: ICallback<void>) => void;
|
|
622
|
+
protected hasEventListeners(): boolean;
|
|
598
623
|
handleError(err: Error): void;
|
|
599
624
|
run(cb?: ICallback<boolean>): void;
|
|
600
625
|
shutdown(cb?: ICallback<boolean>): void;
|
|
@@ -696,10 +721,10 @@ declare class Consumer extends Base {
|
|
|
696
721
|
protected heartbeat: ConsumerHeartbeat | null;
|
|
697
722
|
protected workerRunner: WorkerRunner | null;
|
|
698
723
|
constructor(useMultiplexing?: boolean);
|
|
724
|
+
protected registerSystemEventListeners(): void;
|
|
699
725
|
protected setUpHeartbeat: (cb: ICallback<void>) => void;
|
|
700
726
|
protected tearDownHeartbeat: (cb: ICallback<void>) => void;
|
|
701
727
|
protected setUpConsumerWorkers: (cb: ICallback<void>) => void;
|
|
702
|
-
protected initConsumerEventListeners: (cb: ICallback<void>) => void;
|
|
703
728
|
protected tearDownConsumerWorkers: (cb: ICallback<void>) => void;
|
|
704
729
|
protected runMessageHandlers: (cb: ICallback<void>) => void;
|
|
705
730
|
protected shutdownMessageHandlers: (cb: ICallback<void>) => void;
|
|
@@ -711,8 +736,7 @@ declare class Consumer extends Base {
|
|
|
711
736
|
}
|
|
712
737
|
|
|
713
738
|
declare class Producer extends Base {
|
|
714
|
-
protected
|
|
715
|
-
protected goingUp(): TUnaryFunction<ICallback<void>>[];
|
|
739
|
+
protected registerSystemEventListeners(): void;
|
|
716
740
|
protected enqueue(redisClient: RedisClient, queue: IQueueParams, message: MessageEnvelope, cb: ICallback<void>): void;
|
|
717
741
|
protected produceMessage(redisClient: RedisClient, message: MessageEnvelope, queue: IQueueParams, cb: ICallback<string>): void;
|
|
718
742
|
produce(msg: ProducibleMessage, cb: ICallback<string[]>): void;
|
|
@@ -727,43 +751,6 @@ declare class Message {
|
|
|
727
751
|
deleteMessageById(id: string, cb: ICallback<void>): void;
|
|
728
752
|
}
|
|
729
753
|
|
|
730
|
-
declare abstract class Exchange<TBindingParams, ExchangeType extends EExchangeType> implements IExchange<TBindingParams, ExchangeType> {
|
|
731
|
-
readonly type: ExchangeType;
|
|
732
|
-
readonly bindingParams: TBindingParams;
|
|
733
|
-
exchangeTag: string;
|
|
734
|
-
protected constructor(bindingParams: TBindingParams, type: ExchangeType);
|
|
735
|
-
protected generateExchangeTag(): string;
|
|
736
|
-
getBindingParams(): TBindingParams;
|
|
737
|
-
toJSON(): IExchangeSerialized<TBindingParams, ExchangeType>;
|
|
738
|
-
fromJSON(JSON: Partial<IExchangeSerialized<TBindingParams, ExchangeType>>): void;
|
|
739
|
-
protected abstract validateBindingParams(bindingParams: TBindingParams): TBindingParams;
|
|
740
|
-
abstract getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
declare class ExchangeDirect extends Exchange<TExchangeDirectBindingParams, EExchangeType.DIRECT> {
|
|
744
|
-
constructor(queue: TExchangeDirectBindingParams);
|
|
745
|
-
protected validateBindingParams(queue: TExchangeDirectBindingParams): IQueueParams;
|
|
746
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
declare class ExchangeTopic extends Exchange<TExchangeTopicBindingParams, EExchangeType.TOPIC> {
|
|
750
|
-
constructor(topic: TExchangeTopicBindingParams);
|
|
751
|
-
protected validateBindingParams(topicParams: TExchangeTopicBindingParams): TTopicParams;
|
|
752
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
declare class ExchangeFanOut extends Exchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT> {
|
|
756
|
-
constructor(fanOutName: TExchangeFanOutBindingParams);
|
|
757
|
-
protected validateBindingParams(bindingParams: TExchangeFanOutBindingParams): string;
|
|
758
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
759
|
-
saveExchange(cb: ICallback<void>): void;
|
|
760
|
-
deleteExchange(cb: ICallback<void>): void;
|
|
761
|
-
bindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
762
|
-
unbindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
763
|
-
static getAllExchanges(cb: ICallback<string[]>): void;
|
|
764
|
-
static getQueueExchange(queue: IQueueParams | string, cb: ICallback<ExchangeFanOut | null>): void;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
754
|
declare class Namespace {
|
|
768
755
|
getNamespaces(cb: ICallback<string[]>): void;
|
|
769
756
|
getNamespaceQueues(namespace: string, cb: ICallback<IQueueParams[]>): void;
|
|
@@ -864,4 +851,4 @@ declare class Configuration {
|
|
|
864
851
|
|
|
865
852
|
declare function disconnect(cb: ICallback<void>): void;
|
|
866
853
|
|
|
867
|
-
export { Configuration, Consumer, ConsumerError, ConsumerMessageHandlerAlreadyExistsError, EConsumeMessageDeadLetterCause, EConsumeMessageUnacknowledgedCause, EExchangeType, EMessagePriority, EMessageProperty, EMessagePropertyStatus, EQueueProperty, EQueueType, ExchangeDirect, ExchangeError, ExchangeFanOut, ExchangeFanOutError, ExchangeInvalidDataError, ExchangeTopic, type IConsumableMessage, type IConsumerHeartbeat, type IConsumerHeartbeatPayload, type IConsumerMessageHandlerArgs, type IEventListener, type
|
|
854
|
+
export { Configuration, Consumer, ConsumerError, ConsumerMessageHandlerAlreadyExistsError, EConsumeMessageDeadLetterCause, EConsumeMessageUnacknowledgedCause, EExchangeType, EMessagePriority, EMessageProperty, EMessagePropertyStatus, EQueueProperty, EQueueType, ExchangeDirect, ExchangeError, ExchangeFanOut, ExchangeFanOutError, ExchangeInvalidDataError, ExchangeTopic, type IConsumableMessage, type IConsumerHeartbeat, type IConsumerHeartbeatPayload, type IConsumerMessageHandlerArgs, type IEventListener, type IExchange, type IExchangeSerialized, type IMessageSerialized, type IMessageStateSerialized, type IMessagesConfig, type IMessagesConfigStorage, type IMessagesConfigStorageOptions, type IMessagesConfigStorageOptionsRequired, type IMessagesConfigStorageRequired, type IQueueMessages, type IQueueMessagesCount, type IQueueMessagesPage, type IQueueMessagesPageParams, type IQueueParams, type IQueueProperties, type IQueueRateLimit, type IRedisSMQConfig, type IRedisSMQConfigRequired, Message, MessageDeleteError, MessageDestinationQueueAlreadySetError, MessageDestinationQueueRequiredError, MessageError, MessageExchangeRequiredError, MessageNotFoundError, Namespace, Producer, ProducerError, ProducerInstanceNotRunningError, ProducerMessageNotPublishedError, ProducerMessageNotScheduledError, ProducibleMessage, Queue, QueueAcknowledgedMessages, QueueDeadLetteredMessages, QueueError, QueueExistsError, QueueHasRunningConsumersError, QueueMessageRequeueError, QueueMessages, QueueNamespaceNotFoundError, QueueNotEmptyError, QueueNotFoundError, QueuePendingMessages, QueueRateLimit, QueueRateLimitError, QueueScheduledMessages, type TConsumerMessageHandler, type TConsumerRedisKeys, type TEventListenersConfig, type TExchange, type TExchangeDirectBindingParams, type TExchangeFanOutBindingParams, type TExchangeSerialized, type TExchangeTopicBindingParams, type TMessageConsumeOptions, type TQueueConsumer, type TRedisSMQEvent, type TTopicParams, disconnect };
|
package/dist/index.d.ts
CHANGED
|
@@ -387,60 +387,84 @@ declare enum EConsumeMessageUnacknowledgedCause {
|
|
|
387
387
|
|
|
388
388
|
type TRedisSMQEvent = TEvent & {
|
|
389
389
|
heartbeatTick: (timestamp: number, consumerId: string, heartbeatPayload: IConsumerHeartbeat) => void;
|
|
390
|
-
messagePublished: (messageId: string, queue: IQueueParams) => void;
|
|
390
|
+
messagePublished: (messageId: string, queue: IQueueParams, producerId: string) => void;
|
|
391
391
|
messageAcknowledged: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
392
|
-
messageUnacknowledged: (
|
|
393
|
-
messageDeadLettered: (
|
|
392
|
+
messageUnacknowledged: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string, cause: EConsumeMessageUnacknowledgedCause) => void;
|
|
393
|
+
messageDeadLettered: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string, cause: EConsumeMessageDeadLetterCause) => void;
|
|
394
394
|
messageReceived: (messageId: string, queue: IQueueParams, consumerId: string) => void;
|
|
395
395
|
messageRequeued: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
396
396
|
messageDelayed: (messageId: string, queue: IQueueParams, messageHandlerId: string, consumerId: string) => void;
|
|
397
397
|
};
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
instanceId: string;
|
|
402
|
-
};
|
|
403
|
-
interface IEventListener {
|
|
404
|
-
init(args: TEventListenerInitArgs, cb: ICallback<void>): void;
|
|
399
|
+
interface IEventListener extends EventEmitter<TRedisSMQEvent> {
|
|
400
|
+
init(cb: ICallback<void>): void;
|
|
405
401
|
quit(cb: ICallback<void>): void;
|
|
406
402
|
}
|
|
407
403
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
404
|
+
type TEventListenersConfig = (new () => IEventListener)[];
|
|
405
|
+
|
|
406
|
+
declare abstract class Exchange<TBindingParams, ExchangeType extends EExchangeType> implements IExchange<TBindingParams, ExchangeType> {
|
|
407
|
+
readonly type: ExchangeType;
|
|
408
|
+
readonly bindingParams: TBindingParams;
|
|
409
|
+
exchangeTag: string;
|
|
410
|
+
protected constructor(bindingParams: TBindingParams, type: ExchangeType);
|
|
411
|
+
protected generateExchangeTag(): string;
|
|
412
|
+
getBindingParams(): TBindingParams;
|
|
413
|
+
toJSON(): IExchangeSerialized<TBindingParams, ExchangeType>;
|
|
414
|
+
fromJSON(JSON: Partial<IExchangeSerialized<TBindingParams, ExchangeType>>): void;
|
|
415
|
+
protected abstract validateBindingParams(bindingParams: TBindingParams): TBindingParams;
|
|
416
|
+
abstract getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
declare class ExchangeDirect extends Exchange<TExchangeDirectBindingParams, EExchangeType.DIRECT> {
|
|
420
|
+
constructor(queue: TExchangeDirectBindingParams);
|
|
421
|
+
protected validateBindingParams(queue: TExchangeDirectBindingParams): IQueueParams;
|
|
422
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
declare class ExchangeTopic extends Exchange<TExchangeTopicBindingParams, EExchangeType.TOPIC> {
|
|
426
|
+
constructor(topic: TExchangeTopicBindingParams);
|
|
427
|
+
protected validateBindingParams(topicParams: TExchangeTopicBindingParams): TTopicParams;
|
|
428
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
declare class ExchangeFanOut extends Exchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT> {
|
|
432
|
+
constructor(fanOutName: TExchangeFanOutBindingParams);
|
|
433
|
+
protected validateBindingParams(bindingParams: TExchangeFanOutBindingParams): string;
|
|
434
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
435
|
+
saveExchange(cb: ICallback<void>): void;
|
|
436
|
+
deleteExchange(cb: ICallback<void>): void;
|
|
437
|
+
bindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
438
|
+
unbindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
439
|
+
static getAllExchanges(cb: ICallback<string[]>): void;
|
|
440
|
+
static getQueueExchange(queue: IQueueParams | string, cb: ICallback<ExchangeFanOut | null>): void;
|
|
411
441
|
}
|
|
412
|
-
type IEventListenersConfigRequired = Required<IEventListenersConfig>;
|
|
413
442
|
|
|
414
|
-
type TTopicParams = {
|
|
415
|
-
topic: string;
|
|
416
|
-
ns: string;
|
|
417
|
-
};
|
|
418
443
|
declare enum EExchangeType {
|
|
419
444
|
DIRECT = 0,
|
|
420
445
|
FANOUT = 1,
|
|
421
446
|
TOPIC = 2
|
|
422
447
|
}
|
|
448
|
+
type TTopicParams = {
|
|
449
|
+
topic: string;
|
|
450
|
+
ns: string;
|
|
451
|
+
};
|
|
423
452
|
type TExchangeDirectBindingParams = IQueueParams | string;
|
|
424
|
-
type TExchangeFanOutBindingParams = string;
|
|
425
453
|
type TExchangeTopicBindingParams = TTopicParams | string;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
454
|
+
type TExchangeFanOutBindingParams = string;
|
|
455
|
+
type TExchange = ExchangeDirect | ExchangeTopic | ExchangeFanOut;
|
|
456
|
+
type TExchangeSerialized = ReturnType<ExchangeDirect['toJSON']> | ReturnType<ExchangeTopic['toJSON']> | ReturnType<ExchangeFanOut['toJSON']>;
|
|
457
|
+
|
|
431
458
|
interface IExchangeSerialized<BindingParams, ExchangeType extends EExchangeType> {
|
|
432
459
|
readonly type: ExchangeType;
|
|
433
460
|
readonly bindingParams: BindingParams;
|
|
434
461
|
readonly exchangeTag: string;
|
|
435
462
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
type TExchangeFanOut = IExchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT>;
|
|
442
|
-
type TExchange = TExchangeDirect | TExchangeTopic | TExchangeFanOut;
|
|
443
|
-
type TExchangeSerialized = TExchangeDirectSerialized | TExchangeTopicSerialized | TExchangeFanOutSerialized;
|
|
463
|
+
interface IExchange<BindingParams, ExchangeType extends EExchangeType> extends IExchangeSerialized<BindingParams, ExchangeType> {
|
|
464
|
+
toJSON(): IExchangeSerialized<BindingParams, ExchangeType>;
|
|
465
|
+
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
466
|
+
getBindingParams(): BindingParams;
|
|
467
|
+
}
|
|
444
468
|
|
|
445
469
|
interface IQueueMessages {
|
|
446
470
|
countMessages(queue: string | IQueueParams, cb: ICallback<number>): void;
|
|
@@ -470,13 +494,12 @@ interface IRedisSMQConfig {
|
|
|
470
494
|
namespace?: string;
|
|
471
495
|
logger?: ILoggerConfig;
|
|
472
496
|
messages?: IMessagesConfig;
|
|
473
|
-
eventListeners?:
|
|
497
|
+
eventListeners?: TEventListenersConfig;
|
|
474
498
|
}
|
|
475
499
|
interface IRedisSMQConfigRequired extends Required<IRedisSMQConfig> {
|
|
476
500
|
messages: {
|
|
477
501
|
store: IMessagesConfigStorageRequired;
|
|
478
502
|
};
|
|
479
|
-
eventListeners: IEventListenersConfigRequired;
|
|
480
503
|
}
|
|
481
504
|
|
|
482
505
|
declare class ConsumerError extends RedisSMQError {
|
|
@@ -587,6 +610,7 @@ declare abstract class Base extends EventEmitter<TRedisSMQEvent> {
|
|
|
587
610
|
constructor();
|
|
588
611
|
protected setUpSharedRedisClient: (cb: ICallback<void>) => void;
|
|
589
612
|
protected tearDownSharedRedisClient: (cb: ICallback<void>) => void;
|
|
613
|
+
protected initEventListeners: (cb: ICallback<void>) => void;
|
|
590
614
|
protected registerSystemEventListeners(): void;
|
|
591
615
|
protected goingUp(): TFunction[];
|
|
592
616
|
protected up(cb?: ICallback<boolean>): void;
|
|
@@ -595,6 +619,7 @@ declare abstract class Base extends EventEmitter<TRedisSMQEvent> {
|
|
|
595
619
|
protected getSharedRedisClient(): RedisClient;
|
|
596
620
|
protected registerEventListeners(Ctors: (new () => IEventListener)[], cb: ICallback<void>): void;
|
|
597
621
|
protected tearDownEventListeners: (cb: ICallback<void>) => void;
|
|
622
|
+
protected hasEventListeners(): boolean;
|
|
598
623
|
handleError(err: Error): void;
|
|
599
624
|
run(cb?: ICallback<boolean>): void;
|
|
600
625
|
shutdown(cb?: ICallback<boolean>): void;
|
|
@@ -696,10 +721,10 @@ declare class Consumer extends Base {
|
|
|
696
721
|
protected heartbeat: ConsumerHeartbeat | null;
|
|
697
722
|
protected workerRunner: WorkerRunner | null;
|
|
698
723
|
constructor(useMultiplexing?: boolean);
|
|
724
|
+
protected registerSystemEventListeners(): void;
|
|
699
725
|
protected setUpHeartbeat: (cb: ICallback<void>) => void;
|
|
700
726
|
protected tearDownHeartbeat: (cb: ICallback<void>) => void;
|
|
701
727
|
protected setUpConsumerWorkers: (cb: ICallback<void>) => void;
|
|
702
|
-
protected initConsumerEventListeners: (cb: ICallback<void>) => void;
|
|
703
728
|
protected tearDownConsumerWorkers: (cb: ICallback<void>) => void;
|
|
704
729
|
protected runMessageHandlers: (cb: ICallback<void>) => void;
|
|
705
730
|
protected shutdownMessageHandlers: (cb: ICallback<void>) => void;
|
|
@@ -711,8 +736,7 @@ declare class Consumer extends Base {
|
|
|
711
736
|
}
|
|
712
737
|
|
|
713
738
|
declare class Producer extends Base {
|
|
714
|
-
protected
|
|
715
|
-
protected goingUp(): TUnaryFunction<ICallback<void>>[];
|
|
739
|
+
protected registerSystemEventListeners(): void;
|
|
716
740
|
protected enqueue(redisClient: RedisClient, queue: IQueueParams, message: MessageEnvelope, cb: ICallback<void>): void;
|
|
717
741
|
protected produceMessage(redisClient: RedisClient, message: MessageEnvelope, queue: IQueueParams, cb: ICallback<string>): void;
|
|
718
742
|
produce(msg: ProducibleMessage, cb: ICallback<string[]>): void;
|
|
@@ -727,43 +751,6 @@ declare class Message {
|
|
|
727
751
|
deleteMessageById(id: string, cb: ICallback<void>): void;
|
|
728
752
|
}
|
|
729
753
|
|
|
730
|
-
declare abstract class Exchange<TBindingParams, ExchangeType extends EExchangeType> implements IExchange<TBindingParams, ExchangeType> {
|
|
731
|
-
readonly type: ExchangeType;
|
|
732
|
-
readonly bindingParams: TBindingParams;
|
|
733
|
-
exchangeTag: string;
|
|
734
|
-
protected constructor(bindingParams: TBindingParams, type: ExchangeType);
|
|
735
|
-
protected generateExchangeTag(): string;
|
|
736
|
-
getBindingParams(): TBindingParams;
|
|
737
|
-
toJSON(): IExchangeSerialized<TBindingParams, ExchangeType>;
|
|
738
|
-
fromJSON(JSON: Partial<IExchangeSerialized<TBindingParams, ExchangeType>>): void;
|
|
739
|
-
protected abstract validateBindingParams(bindingParams: TBindingParams): TBindingParams;
|
|
740
|
-
abstract getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
declare class ExchangeDirect extends Exchange<TExchangeDirectBindingParams, EExchangeType.DIRECT> {
|
|
744
|
-
constructor(queue: TExchangeDirectBindingParams);
|
|
745
|
-
protected validateBindingParams(queue: TExchangeDirectBindingParams): IQueueParams;
|
|
746
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
declare class ExchangeTopic extends Exchange<TExchangeTopicBindingParams, EExchangeType.TOPIC> {
|
|
750
|
-
constructor(topic: TExchangeTopicBindingParams);
|
|
751
|
-
protected validateBindingParams(topicParams: TExchangeTopicBindingParams): TTopicParams;
|
|
752
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
declare class ExchangeFanOut extends Exchange<TExchangeFanOutBindingParams, EExchangeType.FANOUT> {
|
|
756
|
-
constructor(fanOutName: TExchangeFanOutBindingParams);
|
|
757
|
-
protected validateBindingParams(bindingParams: TExchangeFanOutBindingParams): string;
|
|
758
|
-
getQueues(cb: ICallback<IQueueParams[]>): void;
|
|
759
|
-
saveExchange(cb: ICallback<void>): void;
|
|
760
|
-
deleteExchange(cb: ICallback<void>): void;
|
|
761
|
-
bindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
762
|
-
unbindQueue(queue: IQueueParams | string, cb: ICallback<void>): void;
|
|
763
|
-
static getAllExchanges(cb: ICallback<string[]>): void;
|
|
764
|
-
static getQueueExchange(queue: IQueueParams | string, cb: ICallback<ExchangeFanOut | null>): void;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
754
|
declare class Namespace {
|
|
768
755
|
getNamespaces(cb: ICallback<string[]>): void;
|
|
769
756
|
getNamespaceQueues(namespace: string, cb: ICallback<IQueueParams[]>): void;
|
|
@@ -864,4 +851,4 @@ declare class Configuration {
|
|
|
864
851
|
|
|
865
852
|
declare function disconnect(cb: ICallback<void>): void;
|
|
866
853
|
|
|
867
|
-
export { Configuration, Consumer, ConsumerError, ConsumerMessageHandlerAlreadyExistsError, EConsumeMessageDeadLetterCause, EConsumeMessageUnacknowledgedCause, EExchangeType, EMessagePriority, EMessageProperty, EMessagePropertyStatus, EQueueProperty, EQueueType, ExchangeDirect, ExchangeError, ExchangeFanOut, ExchangeFanOutError, ExchangeInvalidDataError, ExchangeTopic, type IConsumableMessage, type IConsumerHeartbeat, type IConsumerHeartbeatPayload, type IConsumerMessageHandlerArgs, type IEventListener, type
|
|
854
|
+
export { Configuration, Consumer, ConsumerError, ConsumerMessageHandlerAlreadyExistsError, EConsumeMessageDeadLetterCause, EConsumeMessageUnacknowledgedCause, EExchangeType, EMessagePriority, EMessageProperty, EMessagePropertyStatus, EQueueProperty, EQueueType, ExchangeDirect, ExchangeError, ExchangeFanOut, ExchangeFanOutError, ExchangeInvalidDataError, ExchangeTopic, type IConsumableMessage, type IConsumerHeartbeat, type IConsumerHeartbeatPayload, type IConsumerMessageHandlerArgs, type IEventListener, type IExchange, type IExchangeSerialized, type IMessageSerialized, type IMessageStateSerialized, type IMessagesConfig, type IMessagesConfigStorage, type IMessagesConfigStorageOptions, type IMessagesConfigStorageOptionsRequired, type IMessagesConfigStorageRequired, type IQueueMessages, type IQueueMessagesCount, type IQueueMessagesPage, type IQueueMessagesPageParams, type IQueueParams, type IQueueProperties, type IQueueRateLimit, type IRedisSMQConfig, type IRedisSMQConfigRequired, Message, MessageDeleteError, MessageDestinationQueueAlreadySetError, MessageDestinationQueueRequiredError, MessageError, MessageExchangeRequiredError, MessageNotFoundError, Namespace, Producer, ProducerError, ProducerInstanceNotRunningError, ProducerMessageNotPublishedError, ProducerMessageNotScheduledError, ProducibleMessage, Queue, QueueAcknowledgedMessages, QueueDeadLetteredMessages, QueueError, QueueExistsError, QueueHasRunningConsumersError, QueueMessageRequeueError, QueueMessages, QueueNamespaceNotFoundError, QueueNotEmptyError, QueueNotFoundError, QueuePendingMessages, QueueRateLimit, QueueRateLimitError, QueueScheduledMessages, type TConsumerMessageHandler, type TConsumerRedisKeys, type TEventListenersConfig, type TExchange, type TExchangeDirectBindingParams, type TExchangeFanOutBindingParams, type TExchangeSerialized, type TExchangeTopicBindingParams, type TMessageConsumeOptions, type TQueueConsumer, type TRedisSMQEvent, type TTopicParams, disconnect };
|
package/dist/index.js
CHANGED
|
@@ -262,14 +262,10 @@ function Messages(userConfig) {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
// src/config/event-listeners/event-listeners.ts
|
|
265
|
-
|
|
266
|
-
var defaultConfig4 = {
|
|
267
|
-
consumerEventListeners: [],
|
|
268
|
-
producerEventListeners: []
|
|
269
|
-
};
|
|
265
|
+
var defaultConfig4 = [];
|
|
270
266
|
function EventListeners(userConfig) {
|
|
271
|
-
const { eventListeners =
|
|
272
|
-
return
|
|
267
|
+
const { eventListeners = [] } = userConfig;
|
|
268
|
+
return [...defaultConfig4, ...eventListeners];
|
|
273
269
|
}
|
|
274
270
|
|
|
275
271
|
// src/config/configuration.ts
|
|
@@ -331,11 +327,11 @@ function _destroyCommonRedisClient(cb) {
|
|
|
331
327
|
}
|
|
332
328
|
|
|
333
329
|
// types/consumer/consume-message.ts
|
|
334
|
-
var EConsumeMessageDeadLetterCause = /* @__PURE__ */ ((
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return
|
|
330
|
+
var EConsumeMessageDeadLetterCause = /* @__PURE__ */ ((EConsumeMessageDeadLetterCause2) => {
|
|
331
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["TTL_EXPIRED"] = 0] = "TTL_EXPIRED";
|
|
332
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["RETRY_THRESHOLD_EXCEEDED"] = 1] = "RETRY_THRESHOLD_EXCEEDED";
|
|
333
|
+
EConsumeMessageDeadLetterCause2[EConsumeMessageDeadLetterCause2["PERIODIC_MESSAGE"] = 2] = "PERIODIC_MESSAGE";
|
|
334
|
+
return EConsumeMessageDeadLetterCause2;
|
|
339
335
|
})(EConsumeMessageDeadLetterCause || {});
|
|
340
336
|
var EConsumeMessageUnacknowledgedCause = /* @__PURE__ */ ((EConsumeMessageUnacknowledgedCause3) => {
|
|
341
337
|
EConsumeMessageUnacknowledgedCause3[EConsumeMessageUnacknowledgedCause3["TIMEOUT"] = 0] = "TIMEOUT";
|
|
@@ -347,7 +343,7 @@ var EConsumeMessageUnacknowledgedCause = /* @__PURE__ */ ((EConsumeMessageUnackn
|
|
|
347
343
|
return EConsumeMessageUnacknowledgedCause3;
|
|
348
344
|
})(EConsumeMessageUnacknowledgedCause || {});
|
|
349
345
|
|
|
350
|
-
// types/exchange/
|
|
346
|
+
// types/exchange/common.ts
|
|
351
347
|
var EExchangeType = /* @__PURE__ */ ((EExchangeType2) => {
|
|
352
348
|
EExchangeType2[EExchangeType2["DIRECT"] = 0] = "DIRECT";
|
|
353
349
|
EExchangeType2[EExchangeType2["FANOUT"] = 1] = "FANOUT";
|
|
@@ -724,6 +720,10 @@ var Base = class extends EventEmitter2 {
|
|
|
724
720
|
} else
|
|
725
721
|
cb();
|
|
726
722
|
};
|
|
723
|
+
this.initEventListeners = (cb) => {
|
|
724
|
+
const { eventListeners } = Configuration.getSetConfig();
|
|
725
|
+
this.registerEventListeners(eventListeners, cb);
|
|
726
|
+
};
|
|
727
727
|
this.tearDownEventListeners = (cb) => {
|
|
728
728
|
async2.each(
|
|
729
729
|
this.eventListeners,
|
|
@@ -754,7 +754,7 @@ var Base = class extends EventEmitter2 {
|
|
|
754
754
|
this.on("error", (err) => this.handleError(err));
|
|
755
755
|
}
|
|
756
756
|
goingUp() {
|
|
757
|
-
return [this.setUpSharedRedisClient];
|
|
757
|
+
return [this.setUpSharedRedisClient, this.initEventListeners];
|
|
758
758
|
}
|
|
759
759
|
up(cb) {
|
|
760
760
|
this.powerSwitch.commit();
|
|
@@ -779,24 +779,21 @@ var Base = class extends EventEmitter2 {
|
|
|
779
779
|
Ctors,
|
|
780
780
|
(ctor, key, done) => {
|
|
781
781
|
const instance = new ctor();
|
|
782
|
-
instance.init(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
if (err)
|
|
789
|
-
done(err);
|
|
790
|
-
else {
|
|
791
|
-
this.eventListeners.push(instance);
|
|
792
|
-
done();
|
|
793
|
-
}
|
|
782
|
+
instance.init((err) => {
|
|
783
|
+
if (err)
|
|
784
|
+
done(err);
|
|
785
|
+
else {
|
|
786
|
+
this.eventListeners.push(instance);
|
|
787
|
+
done();
|
|
794
788
|
}
|
|
795
|
-
);
|
|
789
|
+
});
|
|
796
790
|
},
|
|
797
791
|
cb
|
|
798
792
|
);
|
|
799
793
|
}
|
|
794
|
+
hasEventListeners() {
|
|
795
|
+
return !!Configuration.getSetConfig().eventListeners.length;
|
|
796
|
+
}
|
|
800
797
|
handleError(err) {
|
|
801
798
|
if (this.powerSwitch.isGoingUp() || this.powerSwitch.isRunning()) {
|
|
802
799
|
throw err;
|
|
@@ -2888,20 +2885,20 @@ var ConsumeMessage = class {
|
|
|
2888
2885
|
const consumerId = this.messageHandler.getConsumerId();
|
|
2889
2886
|
this.messageHandler.emit(
|
|
2890
2887
|
"messageUnacknowledged",
|
|
2891
|
-
cause,
|
|
2892
2888
|
messageId,
|
|
2893
2889
|
queue,
|
|
2894
2890
|
messageHandlerId,
|
|
2895
|
-
consumerId
|
|
2891
|
+
consumerId,
|
|
2892
|
+
cause
|
|
2896
2893
|
);
|
|
2897
2894
|
if (reply.action === 0 /* DEAD_LETTER */) {
|
|
2898
2895
|
this.messageHandler.emit(
|
|
2899
2896
|
"messageDeadLettered",
|
|
2900
|
-
reply.deadLetterCause,
|
|
2901
2897
|
messageId,
|
|
2902
2898
|
queue,
|
|
2903
2899
|
messageHandlerId,
|
|
2904
|
-
consumerId
|
|
2900
|
+
consumerId,
|
|
2901
|
+
reply.deadLetterCause
|
|
2905
2902
|
);
|
|
2906
2903
|
} else if (reply.action === 2 /* DELAY */) {
|
|
2907
2904
|
this.messageHandler.emit(
|
|
@@ -3028,7 +3025,7 @@ var MessageHandler = class extends EventEmitter3 {
|
|
|
3028
3025
|
});
|
|
3029
3026
|
this.on(
|
|
3030
3027
|
"messageDeadLettered",
|
|
3031
|
-
(
|
|
3028
|
+
(messageId, queue, messageHandlerId, consumerId, cause) => {
|
|
3032
3029
|
this.logger.info(
|
|
3033
3030
|
`Message (ID ${messageId}) dead-lettered (cause ${cause})`
|
|
3034
3031
|
);
|
|
@@ -3036,7 +3033,7 @@ var MessageHandler = class extends EventEmitter3 {
|
|
|
3036
3033
|
);
|
|
3037
3034
|
this.on(
|
|
3038
3035
|
"messageUnacknowledged",
|
|
3039
|
-
(
|
|
3036
|
+
(messageId, queue, messageHandlerId, consumerId, cause) => {
|
|
3040
3037
|
this.logger.info(
|
|
3041
3038
|
`Message (ID ${messageId}) unacknowledged (cause ${cause})`
|
|
3042
3039
|
);
|
|
@@ -3929,12 +3926,6 @@ var Consumer = class extends Base {
|
|
|
3929
3926
|
this.workerRunner.addWorker(new publish_scheduled_worker_default(redisClient2, true));
|
|
3930
3927
|
this.workerRunner.run();
|
|
3931
3928
|
};
|
|
3932
|
-
this.initConsumerEventListeners = (cb) => {
|
|
3933
|
-
this.registerEventListeners(
|
|
3934
|
-
Configuration.getSetConfig().eventListeners.consumerEventListeners,
|
|
3935
|
-
cb
|
|
3936
|
-
);
|
|
3937
|
-
};
|
|
3938
3929
|
this.tearDownConsumerWorkers = (cb) => {
|
|
3939
3930
|
if (this.workerRunner) {
|
|
3940
3931
|
this.workerRunner.quit(() => {
|
|
@@ -3961,10 +3952,29 @@ var Consumer = class extends Base {
|
|
|
3961
3952
|
this.messageHandlerRunner = useMultiplexing ? new MultiplexedMessageHandlerRunner(this, nsLogger) : new MessageHandlerRunner(this, nsLogger);
|
|
3962
3953
|
this.redisKeys = redisKeys.getConsumerKeys(this.getId());
|
|
3963
3954
|
}
|
|
3955
|
+
registerSystemEventListeners() {
|
|
3956
|
+
super.registerSystemEventListeners();
|
|
3957
|
+
if (this.hasEventListeners()) {
|
|
3958
|
+
this.on("messageAcknowledged", (...args) => {
|
|
3959
|
+
this.eventListeners.forEach(
|
|
3960
|
+
(i) => i.emit("messageAcknowledged", ...args)
|
|
3961
|
+
);
|
|
3962
|
+
});
|
|
3963
|
+
this.on("messageUnacknowledged", (...args) => {
|
|
3964
|
+
this.eventListeners.forEach(
|
|
3965
|
+
(i) => i.emit("messageUnacknowledged", ...args)
|
|
3966
|
+
);
|
|
3967
|
+
});
|
|
3968
|
+
this.on("messageDeadLettered", (...args) => {
|
|
3969
|
+
this.eventListeners.forEach(
|
|
3970
|
+
(i) => i.emit("messageDeadLettered", ...args)
|
|
3971
|
+
);
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3964
3975
|
goingUp() {
|
|
3965
3976
|
return super.goingUp().concat([
|
|
3966
3977
|
this.setUpHeartbeat,
|
|
3967
|
-
this.initConsumerEventListeners,
|
|
3968
3978
|
this.runMessageHandlers,
|
|
3969
3979
|
this.setUpConsumerWorkers
|
|
3970
3980
|
]);
|
|
@@ -4053,17 +4063,13 @@ function _scheduleMessage(mixed, message, cb) {
|
|
|
4053
4063
|
|
|
4054
4064
|
// src/lib/producer/producer.ts
|
|
4055
4065
|
var Producer = class extends Base {
|
|
4056
|
-
|
|
4057
|
-
super(
|
|
4058
|
-
this.
|
|
4059
|
-
this.
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
};
|
|
4064
|
-
}
|
|
4065
|
-
goingUp() {
|
|
4066
|
-
return super.goingUp().concat([this.initProducerEventListeners]);
|
|
4066
|
+
registerSystemEventListeners() {
|
|
4067
|
+
super.registerSystemEventListeners();
|
|
4068
|
+
if (this.hasEventListeners()) {
|
|
4069
|
+
this.on("messagePublished", (...args) => {
|
|
4070
|
+
this.eventListeners.forEach((i) => i.emit("messagePublished", ...args));
|
|
4071
|
+
});
|
|
4072
|
+
}
|
|
4067
4073
|
}
|
|
4068
4074
|
enqueue(redisClient2, queue, message, cb) {
|
|
4069
4075
|
var _a;
|
|
@@ -4133,7 +4139,7 @@ var Producer = class extends Base {
|
|
|
4133
4139
|
cb(err);
|
|
4134
4140
|
else {
|
|
4135
4141
|
this.logger.info(`Message (ID ${messageId}) has been published.`);
|
|
4136
|
-
this.emit("messagePublished", messageId, queue);
|
|
4142
|
+
this.emit("messagePublished", messageId, queue, this.id);
|
|
4137
4143
|
cb(null, messageId);
|
|
4138
4144
|
}
|
|
4139
4145
|
});
|
|
@@ -44,40 +44,45 @@ local function updateQueue()
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
local function deleteMessage()
|
|
47
|
-
local deleted = 0;
|
|
48
47
|
local messageStatus = redis.call("HGET", keyMessage, EMessagePropertyStatus)
|
|
49
|
-
if messageStatus
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
if messageStatus == false then
|
|
49
|
+
return 'MESSAGE_NOT_FOUND'
|
|
50
|
+
end
|
|
51
|
+
if messageStatus == EMessagePropertyStatusProcessing then
|
|
52
|
+
return 'MESSAGE_IN_PROCESS'
|
|
53
|
+
end
|
|
54
|
+
local deleted = 0;
|
|
55
|
+
if messageStatus == EMessagePropertyStatusAcknowledged then
|
|
56
|
+
deleted = redis.call("LREM", keyQueueAcknowledged, 1, messageId)
|
|
57
|
+
elseif messageStatus == EMessagePropertyStatusDeadLettered then
|
|
58
|
+
deleted = redis.call("LREM", keyQueueDL, 1, messageId)
|
|
59
|
+
elseif messageStatus == EMessagePropertyStatusScheduled then
|
|
60
|
+
deleted = redis.call("ZREM", keyScheduledMessages, messageId)
|
|
61
|
+
redis.call("ZREM", keyQueueScheduled, messageId)
|
|
62
|
+
elseif messageStatus == EMessagePropertyStatusUnackDelaying then
|
|
63
|
+
deleted = redis.call("LREM", keyDelayedMessages, 1, messageId)
|
|
64
|
+
elseif messageStatus == EMessagePropertyStatusUnackRequeuing then
|
|
65
|
+
deleted = redis.call("LREM", keyRequeueMessages, 1, messageId)
|
|
66
|
+
elseif messageStatus == EMessagePropertyStatusPending then
|
|
67
|
+
local queueType = redis.call("HGET", keyQueueProperties, EQueuePropertyQueueType)
|
|
68
|
+
if queueType ~= false then
|
|
69
|
+
if queueType == EQueuePropertyQueueTypePriorityQueue then
|
|
70
|
+
deleted = redis.call("ZREM", keyPriorityQueuePending, messageId)
|
|
71
|
+
end
|
|
72
|
+
if queueType == EQueuePropertyQueueTypeFIFOQueue or queueType == EQueuePropertyQueueTypeLIFOQueue then
|
|
73
|
+
deleted = redis.call("LREM", keyQueuePending, 1, messageId)
|
|
70
74
|
end
|
|
71
75
|
end
|
|
72
76
|
end
|
|
73
77
|
if deleted == 1 then
|
|
74
78
|
redis.call("DEL", keyMessage)
|
|
75
|
-
return
|
|
79
|
+
return 'OK'
|
|
76
80
|
end
|
|
77
|
-
return
|
|
81
|
+
return 'MESSAGE_NOT_DELETED'
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
|
|
85
|
+
local deleteMessageStatus = 'INVALID_PARAMETERS'
|
|
81
86
|
|
|
82
87
|
if #ARGV > argvIndexOffset then
|
|
83
88
|
for index in pairs(ARGV) do
|
|
@@ -91,13 +96,13 @@ if #ARGV > argvIndexOffset then
|
|
|
91
96
|
keyQueueScheduled = KEYS[keyIndexOffset + 6]
|
|
92
97
|
keyPriorityQueuePending = KEYS[keyIndexOffset + 7]
|
|
93
98
|
keyIndexOffset = keyIndexOffset + 7
|
|
94
|
-
|
|
95
|
-
if
|
|
96
|
-
|
|
99
|
+
deleteMessageStatus = deleteMessage()
|
|
100
|
+
if deleteMessageStatus ~= 'OK' then
|
|
101
|
+
break
|
|
97
102
|
end
|
|
103
|
+
updateQueue()
|
|
98
104
|
end
|
|
99
105
|
end
|
|
100
|
-
return 'OK'
|
|
101
106
|
end
|
|
102
107
|
|
|
103
|
-
return
|
|
108
|
+
return deleteMessageStatus
|