redis-smq 8.0.0-rc.27 → 8.0.0-rc.28
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 +22 -0
- package/CONTRIBUTING.md +20 -0
- package/README.md +44 -112
- package/dist/cjs/src/lib/consumer/consumer-queues.d.ts +1 -3
- package/dist/cjs/src/lib/consumer/consumer-queues.js +12 -28
- package/dist/cjs/src/lib/consumer/message-handler/message-handler/message-handler.js +12 -12
- package/dist/cjs/src/lib/consumer/message-handler/processing-queue/processing-queue.js +66 -70
- package/dist/cjs/src/lib/namespace/namespace.js +73 -93
- package/dist/cjs/src/lib/producer/producer.d.ts +1 -1
- package/dist/cjs/src/lib/producer/producer.js +77 -84
- package/dist/cjs/src/lib/queue/queue.js +53 -71
- package/dist/esm/src/lib/consumer/consumer-queues.d.ts +1 -3
- package/dist/esm/src/lib/consumer/consumer-queues.js +13 -29
- package/dist/esm/src/lib/consumer/message-handler/message-handler/message-handler.js +12 -12
- package/dist/esm/src/lib/consumer/message-handler/processing-queue/processing-queue.js +66 -70
- package/dist/esm/src/lib/namespace/namespace.js +73 -93
- package/dist/esm/src/lib/producer/producer.d.ts +1 -1
- package/dist/esm/src/lib/producer/producer.js +77 -84
- package/dist/esm/src/lib/queue/queue.js +53 -71
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
## [8.0.0-rc.28](https://github.com/weyoss/redis-smq/compare/v8.0.0-rc.27...v8.0.0-rc.28) (2025-02-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **message:** revert back shutdown method to arrow function ([c4e5ceb](https://github.com/weyoss/redis-smq/commit/c4e5cebb4d9fbd91889618669765698cb80cd044))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Documentation
|
|
12
|
+
|
|
13
|
+
* **api:** enhance class documentation with detailed descriptions and examples ([67f8a21](https://github.com/weyoss/redis-smq/commit/67f8a21c039e41301e8bfcf2c4ffc4319b02424d))
|
|
14
|
+
* **api:** separate error classes from main classes ([4aa850e](https://github.com/weyoss/redis-smq/commit/4aa850ed5411906d4a38c32a673cf2021498c294))
|
|
15
|
+
* **README:** update HTTP REST API reference link ([9e20a6c](https://github.com/weyoss/redis-smq/commit/9e20a6c08bf47b1a581129f922c9922c64cb7e3d))
|
|
16
|
+
* update logo, improve content readability ([7c921d4](https://github.com/weyoss/redis-smq/commit/7c921d406e05961d92769f2a43c40f7fa955d5fa))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Codebase Refactoring
|
|
20
|
+
|
|
21
|
+
* improve code structure and readability ([5b4a47c](https://github.com/weyoss/redis-smq/commit/5b4a47cdc1139507a724d1d48202f6d8c6074174))
|
|
22
|
+
|
|
1
23
|
# Changelog
|
|
2
24
|
|
|
3
25
|
## [8.0.0-rc.27](https://github.com/weyoss/redis-smq/compare/v8.0.0-rc.26...v8.0.0-rc.27) (2025-01-09)
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Contributions
|
|
2
|
+
|
|
3
|
+
If you want to make any project better, your contributions are very welcome!
|
|
4
|
+
|
|
5
|
+
## Pull requests
|
|
6
|
+
|
|
7
|
+
It is best to open an issue in GitHub about what you want to implement / change or to suggest new features.
|
|
8
|
+
|
|
9
|
+
Before submitting any pull request please make sure that your code does not stick out and consistent with the project
|
|
10
|
+
coding style. You can check the status of your coding style by simply running `npm run lint`.
|
|
11
|
+
|
|
12
|
+
Cover your code with new tests if needed. Only fully tested changes are accepted.
|
|
13
|
+
|
|
14
|
+
Each time when you are ready to submit your changes don't forget to run `npm test` to check that your code is complying
|
|
15
|
+
with eslint project rules and that all of the tests are successfully completed.
|
|
16
|
+
|
|
17
|
+
## Bugs
|
|
18
|
+
|
|
19
|
+
If you find any bugs, please do not hesitate to open an issue in GitHub including the case to reproduce the bug
|
|
20
|
+
when possible.
|
package/README.md
CHANGED
|
@@ -1,142 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
> Currently, RedisSMQ is going under heavy development. Pre-releases at any time may introduce new commits with breaking changes.
|
|
3
|
-
> The master branch always reflects the most recent changes. To view the latest release reference see [RedisSMQ v7.2.3](https://github.com/weyoss/redis-smq/tree/v7.2.3)
|
|
1
|
+
[](https://github.com/weyoss/redis-smq)
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
<p><a href="https://github.com/weyoss/redis-smq"><img alt="RedisSMQ" src="./logo.png?v=202312182134" /></a></p>
|
|
7
|
-
<p>A simple high-performance Redis message queue for Node.js.</p>
|
|
8
|
-
<p>
|
|
9
|
-
<a href="https://github.com/weyoss/redis-smq/actions/workflows/tests.yml"><img src="https://github.com/weyoss/redis-smq/actions/workflows/tests.yml/badge.svg" alt="Tests" style="max-width:100%;" /></a>
|
|
10
|
-
<a href="https://github.com/weyoss/redis-smq/actions/workflows/codeql.yml" rel="nofollow"><img src="https://github.com/weyoss/redis-smq/actions/workflows/codeql.yml/badge.svg" alt="Code quality" /></a>
|
|
11
|
-
<a href="https://codecov.io/github/weyoss/redis-smq?branch=master" rel="nofollow"><img src="https://img.shields.io/codecov/c/github/weyoss/redis-smq" alt="Coverage Status" /></a>
|
|
12
|
-
<a href="https://npmjs.org/package/redis-smq" rel="nofollow"><img src="https://img.shields.io/npm/v/redis-smq.svg" alt="NPM version" /></a>
|
|
13
|
-
<a href="https://npmjs.org/package/redis-smq" rel="nofollow"><img src="https://img.shields.io/npm/dm/redis-smq.svg" alt="NPM downloads" /></a>
|
|
14
|
-
</p>
|
|
15
|
-
</div>
|
|
3
|
+
A High-Performance Redis Simple Message Queue for Node.js
|
|
16
4
|
|
|
17
|
-
|
|
5
|
+
[](https://github.com/weyoss/redis-smq/actions/workflows/tests.yml)
|
|
6
|
+
[](https://github.com/weyoss/redis-smq/actions/workflows/codeql.yml)
|
|
7
|
+
[](https://codecov.io/github/weyoss/redis-smq?branch=master)
|
|
8
|
+
[](https://github.com/weyoss/redis-smq/releases)
|
|
9
|
+

|
|
18
10
|
|
|
19
|
-
|
|
11
|
+
**Key Features**
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
* [High-performance message processing](docs/performance.md)
|
|
14
|
+
* [Flexible producer/consumer model with multi-queue producers and consumers](docs/consuming-messages.md)
|
|
15
|
+
* [Different exchange types (Direct, Topic, FanOut) for publishing messages to one or multiple queues](docs/message-exchanges.md)
|
|
16
|
+
* [Two delivery models (Point-2-Point and Pub/Sub)](docs/queue-delivery-models.md) with reliable delivery and configurable retry modes
|
|
17
|
+
* [Three queuing strategies (FIFO, LIFO, Priority Queues)](docs/queues.md)
|
|
18
|
+
* [Message handler worker threads for sandboxing and performance improvement](docs/message-handler-worker-threads.md)
|
|
19
|
+
* [Message expiration and consumption timeout](docs/messages.md)
|
|
20
|
+
* [Queue rate limiting for controlling message consumption rates](docs/queue-rate-limiting.md)
|
|
21
|
+
* [Built-in scheduler for delayed message delivery and repeating messages](docs/scheduling-messages.md)
|
|
22
|
+
* [RESTful API](docs/redis-smq-rest-api.md) and [Web UI](docs/redis-smq-web-ui.md) for interacting with the message queue
|
|
23
|
+
* [Support for ESM and CJS modules](docs/esm-cjs-modules.md)
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
* Flexible Producer/Consumer model which offers [Multi-Queue Producers](docs/producing-messages.md) & [Multi-Queue Consumers](docs/consuming-messages.md).
|
|
25
|
-
* RedisSMQ offers different exchange types: [Direct Exchange](docs/message-exchanges.md#direct-exchange), [Topic Exchange](docs/message-exchanges.md#topic-exchange), and [FanOut Exchange](docs/message-exchanges.md#fanout-exchange) for publishing a message to one or multiple queues.
|
|
26
|
-
* Supports [Point-2-Point](docs/queue-delivery-models.md#point-2-point-delivery-model) and [Pub/Sub](docs/queue-delivery-models.md#pubsub-delivery-model) [delivery models](docs/queue-delivery-models.md).
|
|
27
|
-
* Both [delivery models](docs/queue-delivery-models.md) are reliable. For cases of failure, while delivering/consuming messages, [at-least-once](docs/api/classes/ProducibleMessage.md#setretrythreshold) and [at-most-once](docs/api/classes/ProducibleMessage.md#setretrythreshold) modes may be configured.
|
|
28
|
-
* [3 queuing strategies](docs/queues.md): [FIFO queues](docs/queues.md#fifo-first-in-first-out-queues), [LIFO queues](docs/queues.md#lifo-last-in-first-out-queues), and [Priority Queues](docs/queues.md#priority-queues).
|
|
29
|
-
* [Message Handler Worker Threads](docs/message-handler-worker-threads.md) which allow sandboxing and running your message handler from a separate isolated thread and without affecting the performance of other message handlers from the same consumer.
|
|
30
|
-
* Messages can be [set to expire](docs/api/classes/ProducibleMessage.md#setttl) when not delivered within a given amount of time or to have a [consumption timeout](docs/api/classes/ProducibleMessage.md#setconsumetimeout) while being in process.
|
|
31
|
-
* Queues may be [rate Limited](docs/queue-rate-limiting.md) to control the rate at which the messages are consumed.
|
|
32
|
-
* Has a builtin [scheduler](docs/scheduling-messages.md) allowing messages [to be delayed](docs/api/classes/ProducibleMessage.md#setscheduleddelay), [to be delivered for N times](docs/api/classes/ProducibleMessage.md#setscheduledrepeat) with an optional [period between deliveries](docs/api/classes/ProducibleMessage.md#setscheduledrepeatperiod), or simply [to be scheduled using CRON expressions](docs/api/classes/ProducibleMessage.md#setscheduledcron).
|
|
33
|
-
* Provides [an HTTP interface](https://github.com/weyoss/redis-smq-rest-api) to interact with the message queue using a RESTful API.
|
|
34
|
-
* RedisSMQ can be managed also from your [web browser](https://github.com/weyoss/redis-smq-monitor-client).
|
|
35
|
-
* Either [node-redis](https://github.com/redis/node-redis) or [ioredis](https://github.com/luin/ioredis) can be used as a Redis client.
|
|
36
|
-
* [Highly optimized](https://lgtm.com/projects/g/weyoss/redis-smq/context:javascript), implemented using pure callbacks, with small memory footprint and no memory leaks. See [Callback vs Promise vs Async/Await benchmarks](https://gist.github.com/weyoss/24f9ecbda175d943a48cb7ec38bde821).
|
|
37
|
-
* [Both ESM & CJS modules are supported](docs/esm-cjs-modules.md).
|
|
25
|
+
**Use Cases**
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
- Managing background tasks, such as email sending or data processing.
|
|
28
|
+
- Efficiently scheduling and retrying tasks.
|
|
29
|
+
- Communication between multiple services in microservices architectures.
|
|
30
|
+
- Handling real-time events in gaming, IoT, or analytics systems.
|
|
40
31
|
|
|
41
|
-
|
|
32
|
+
**Installation and Usage**
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
:rocket: RC's are now available for RedisSMQ v8! The v8 release will bring major improvements and new features. Some of them are:
|
|
46
|
-
|
|
47
|
-
- [x] Message queue codebase refactoring and optimizations.
|
|
48
|
-
- [x] Message storage and handling improvements.
|
|
49
|
-
- [x] Message status which allows to retrieve, at any time, the status of a message by its ID.
|
|
50
|
-
- [x] [Pub/Sub Delivery Model and Consumer Groups](docs/queue-delivery-models.md#pubsub-delivery-model).
|
|
51
|
-
- [x] Message handlers sandboxing and message processing performance improvement with [Message Handler Worker Threads](docs/message-handler-worker-threads.md).
|
|
52
|
-
- [x] Cross-system event propagation based on [EventBus](docs/event-bus.md).
|
|
53
|
-
- [x] Better error handling aiming at reporting fatal errors to the application whenever it is possible and without crashing the main process.
|
|
54
|
-
- [x] [ESM Modules Support](docs/esm-cjs-modules.md).
|
|
55
|
-
|
|
56
|
-
Current RedisSMQ v8 RC status:
|
|
57
|
-
|
|
58
|
-
- [x] RedisSMQ Common Library
|
|
59
|
-
- [x] RedisSMQ
|
|
60
|
-
- [x] [RESTful API](https://github.com/weyoss/redis-smq-rest-api)
|
|
61
|
-
- [ ] Web UI (WIP)
|
|
62
|
-
|
|
63
|
-
If you wish to get the latest updates early feel free to try RedisSMQ v8 RC. Do not hesitate to report any bug or issue if encountered.
|
|
64
|
-
|
|
65
|
-
Otherwise, stay with [RedisSMQ v7](https://github.com/weyoss/redis-smq/tree/v7.2.3) if you are looking for a fully working release with an HTTP API and a Web UI.
|
|
66
|
-
|
|
67
|
-
## Installation
|
|
68
|
-
|
|
69
|
-
```shell
|
|
34
|
+
To get started with RedisSMQ, you can install the library using npm:
|
|
35
|
+
```bash
|
|
70
36
|
npm i redis-smq@rc
|
|
71
37
|
```
|
|
72
|
-
|
|
73
|
-
Considerations:
|
|
74
|
-
|
|
75
|
-
- Minimal Node.js version is >= 18 (RedisSMQ is tested under current active LTS and maintenance LTS Node.js releases).
|
|
76
|
-
- Minimal Redis server version is 4.0.0.
|
|
77
|
-
|
|
78
|
-
## Usage
|
|
79
|
-
|
|
80
|
-
RedisSMQ provides 3 classes in order to work with the message queue: `ProducibleMessage`, `Producer`, and `Consumer`.
|
|
81
|
-
|
|
82
|
-
Producers and consumers exchange data using one or multiple queues that may be created using the [Queue Class](docs/api/classes/Queue.md).
|
|
83
|
-
|
|
84
|
-
A queue is responsible for holding messages which are produced by producers and are delivered to consumers.
|
|
85
|
-
|
|
86
|
-
### Creating a queue
|
|
87
|
-
|
|
38
|
+
Create a queue, produce a message, and consume it using the provided classes and methods:
|
|
88
39
|
```javascript
|
|
40
|
+
// Creating a queue
|
|
89
41
|
const queue = new Queue();
|
|
90
|
-
queue.save(
|
|
91
|
-
'my_queue',
|
|
92
|
-
EQueueType.LIFO_QUEUE,
|
|
93
|
-
EQueueDeliveryModel.POINT_TO_POINT,
|
|
94
|
-
(err) => {
|
|
42
|
+
queue.save('my_queue', EQueueType.LIFO_QUEUE, EQueueDeliveryModel.POINT_TO_POINT, (err) => {
|
|
95
43
|
if (err) console.error(err);
|
|
96
|
-
|
|
97
|
-
);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
In the example above we are defining a [LIFO queue](docs/queues.md#lifo-last-in-first-out-queues) with a [POINT-2-POINT delivery model](docs/queue-delivery-models.md#point-2-point-delivery-model).
|
|
101
|
-
|
|
102
|
-
See [Queues](docs/queues.md) for more details.
|
|
103
|
-
|
|
104
|
-
### Producing a message
|
|
44
|
+
});
|
|
105
45
|
|
|
106
|
-
|
|
46
|
+
// Producing a message
|
|
107
47
|
const msg = new ProducibleMessage();
|
|
108
48
|
msg.setQueue('my_queue').setBody('Hello Word!');
|
|
109
49
|
producer.produce(msg, (err, ids) => {
|
|
110
|
-
|
|
111
|
-
|
|
50
|
+
if (err) console.error(err);
|
|
51
|
+
else console.log(`Produced message IDs are: ${ids.join(', ')}`);
|
|
112
52
|
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
See [Producing Messages](docs/producing-messages.md) for more details.
|
|
116
53
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```javascript
|
|
54
|
+
// Consuming a message
|
|
120
55
|
const consumer = new Consumer();
|
|
121
56
|
const messageHandler = (msg, cb) => {
|
|
122
|
-
|
|
123
|
-
|
|
57
|
+
console.log(msg.body);
|
|
58
|
+
cb(); // Acknowledging
|
|
124
59
|
};
|
|
125
60
|
consumer.consume('my_queue', messageHandler, (err) => {
|
|
126
|
-
|
|
61
|
+
if (err) console.error(err);
|
|
127
62
|
});
|
|
128
63
|
```
|
|
64
|
+
**Documentation**
|
|
129
65
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
## Documentation
|
|
133
|
-
|
|
134
|
-
See [RedisSMQ Docs](docs/README.md) for more details.
|
|
66
|
+
For more information, visit the [RedisSMQ Docs](docs/README.md).
|
|
135
67
|
|
|
136
|
-
|
|
68
|
+
**Contributing**
|
|
137
69
|
|
|
138
|
-
|
|
70
|
+
Interested in contributing to this project? Please check out our [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
139
71
|
|
|
140
|
-
|
|
72
|
+
**License**
|
|
141
73
|
|
|
142
|
-
[MIT](https://github.com/weyoss/redis-smq/blob/master/LICENSE)
|
|
74
|
+
RedisSMQ is released under the [MIT License](https://github.com/weyoss/redis-smq/blob/master/LICENSE).
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ICallback, IRedisClient
|
|
1
|
+
import { ICallback, IRedisClient } from 'redis-smq-common';
|
|
2
2
|
import { IQueueParams, TQueueConsumer } from '../queue/index.js';
|
|
3
3
|
export declare const consumerQueues: {
|
|
4
|
-
removeConsumer(multi: IRedisTransaction, queue: IQueueParams, consumerId: string): void;
|
|
5
4
|
getQueueConsumers(client: IRedisClient, queue: IQueueParams, transform: boolean, cb: ICallback<Record<string, TQueueConsumer | string>>): void;
|
|
6
5
|
getQueueConsumerIds(client: IRedisClient, queue: IQueueParams, cb: ICallback<string[]>): void;
|
|
7
|
-
countQueueConsumers(client: IRedisClient, queue: IQueueParams, cb: ICallback<number>): void;
|
|
8
6
|
getConsumerQueues(client: IRedisClient, consumerId: string, cb: ICallback<IQueueParams[]>): void;
|
|
9
7
|
};
|
|
10
8
|
//# sourceMappingURL=consumer-queues.d.ts.map
|
|
@@ -4,48 +4,32 @@ exports.consumerQueues = void 0;
|
|
|
4
4
|
const redis_smq_common_1 = require("redis-smq-common");
|
|
5
5
|
const redis_keys_js_1 = require("../../common/redis-keys/redis-keys.js");
|
|
6
6
|
exports.consumerQueues = {
|
|
7
|
-
removeConsumer(multi, queue, consumerId) {
|
|
8
|
-
const { keyQueueConsumers } = redis_keys_js_1.redisKeys.getQueueKeys(queue, null);
|
|
9
|
-
const { keyConsumerQueues } = redis_keys_js_1.redisKeys.getConsumerKeys(consumerId);
|
|
10
|
-
multi.hdel(keyQueueConsumers, consumerId);
|
|
11
|
-
multi.srem(keyConsumerQueues, JSON.stringify(queue));
|
|
12
|
-
},
|
|
13
7
|
getQueueConsumers(client, queue, transform, cb) {
|
|
14
8
|
const { keyQueueConsumers } = redis_keys_js_1.redisKeys.getQueueKeys(queue, null);
|
|
15
9
|
client.hgetall(keyQueueConsumers, (err, reply) => {
|
|
16
10
|
if (err)
|
|
17
|
-
cb(err);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
cb(null, consumers);
|
|
29
|
-
}
|
|
11
|
+
return cb(err);
|
|
12
|
+
const consumers = reply !== null && reply !== void 0 ? reply : {};
|
|
13
|
+
if (!transform)
|
|
14
|
+
return cb(null, consumers);
|
|
15
|
+
const data = {};
|
|
16
|
+
redis_smq_common_1.async.eachIn(consumers, (item, key, done) => {
|
|
17
|
+
data[key] = JSON.parse(item);
|
|
18
|
+
done();
|
|
19
|
+
}, () => cb(null, data));
|
|
30
20
|
});
|
|
31
21
|
},
|
|
32
22
|
getQueueConsumerIds(client, queue, cb) {
|
|
33
23
|
const { keyQueueConsumers } = redis_keys_js_1.redisKeys.getQueueKeys(queue, null);
|
|
34
24
|
client.hkeys(keyQueueConsumers, cb);
|
|
35
25
|
},
|
|
36
|
-
countQueueConsumers(client, queue, cb) {
|
|
37
|
-
const { keyQueueConsumers } = redis_keys_js_1.redisKeys.getQueueKeys(queue, null);
|
|
38
|
-
client.hlen(keyQueueConsumers, cb);
|
|
39
|
-
},
|
|
40
26
|
getConsumerQueues(client, consumerId, cb) {
|
|
41
27
|
const { keyConsumerQueues } = redis_keys_js_1.redisKeys.getConsumerKeys(consumerId);
|
|
42
28
|
client.smembers(keyConsumerQueues, (err, reply) => {
|
|
43
29
|
if (err)
|
|
44
|
-
cb(err);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
cb(null, queues);
|
|
48
|
-
}
|
|
30
|
+
return cb(err);
|
|
31
|
+
const queues = (reply !== null && reply !== void 0 ? reply : []).map((i) => JSON.parse(i));
|
|
32
|
+
cb(null, queues);
|
|
49
33
|
});
|
|
50
34
|
},
|
|
51
35
|
};
|
|
@@ -108,8 +108,7 @@ class MessageHandler extends redis_smq_common_1.Runnable {
|
|
|
108
108
|
cleanUp(cb) {
|
|
109
109
|
const redisClient = this.redisClient.getInstance();
|
|
110
110
|
if (redisClient instanceof Error) {
|
|
111
|
-
cb();
|
|
112
|
-
return void 0;
|
|
111
|
+
return cb();
|
|
113
112
|
}
|
|
114
113
|
processing_queue_js_1.processingQueue.unknowledgeMessage(redisClient, this.consumerId, [this.queue.queueParams], this.logger, index_js_3.EMessageUnknowledgmentReason.OFFLINE_MESSAGE_HANDLER, () => cb());
|
|
115
114
|
}
|
|
@@ -158,17 +157,18 @@ class MessageHandler extends redis_smq_common_1.Runnable {
|
|
|
158
157
|
return void 0;
|
|
159
158
|
}
|
|
160
159
|
redisClient.runScript(scripts_js_1.ELuaScriptName.FETCH_MESSAGE_FOR_PROCESSING, keys, argv, (err, reply) => {
|
|
161
|
-
if (err)
|
|
162
|
-
this.handleError(err);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const message = (0, _from_message_js_1._fromMessage)(msg, index_js_2.EMessagePropertyStatus.PROCESSING, state);
|
|
170
|
-
this.consumeMessage.handleReceivedMessage(message);
|
|
160
|
+
if (err) {
|
|
161
|
+
return this.handleError(err);
|
|
162
|
+
}
|
|
163
|
+
if (!reply) {
|
|
164
|
+
return this.handleError(new redis_smq_common_1.CallbackEmptyReplyError());
|
|
165
|
+
}
|
|
166
|
+
if (!Array.isArray(reply)) {
|
|
167
|
+
return this.handleError(new redis_smq_common_1.CallbackInvalidReplyError());
|
|
171
168
|
}
|
|
169
|
+
const [state, msg] = reply;
|
|
170
|
+
const message = (0, _from_message_js_1._fromMessage)(msg, index_js_2.EMessagePropertyStatus.PROCESSING, state);
|
|
171
|
+
this.consumeMessage.handleReceivedMessage(message);
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -31,49 +31,40 @@ function getMessageUnknowledgementAction(message, unacknowledgedReason) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
const delay = message.producibleMessage.getRetryDelay();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
action: index_js_4.EMessageUnknowledgmentAction.REQUEUE,
|
|
41
|
-
};
|
|
34
|
+
return delay
|
|
35
|
+
? { action: index_js_4.EMessageUnknowledgmentAction.DELAY }
|
|
36
|
+
: { action: index_js_4.EMessageUnknowledgmentAction.REQUEUE };
|
|
42
37
|
}
|
|
43
38
|
function unknowledgeProcessingQueueMessage(redisClient, consumerId, queue, unknowledgmentReason, keys, args, unacknowledgementStatus, done) {
|
|
44
|
-
args.push(JSON.stringify(queue));
|
|
45
|
-
args.push(consumerId);
|
|
39
|
+
args.push(JSON.stringify(queue), consumerId);
|
|
46
40
|
const { keyConsumerQueues } = redis_keys_js_1.redisKeys.getConsumerKeys(consumerId);
|
|
47
41
|
const { keyQueueProcessing } = redis_keys_js_1.redisKeys.getQueueConsumerKeys(queue, consumerId);
|
|
48
42
|
const { keyQueueDL, keyQueueProcessingQueues, keyQueueConsumers, keyQueueProperties, keyQueueDelayed, keyQueueRequeued, } = redis_keys_js_1.redisKeys.getQueueKeys(queue, null);
|
|
49
43
|
keys.push(keyQueueProcessing, keyQueueDelayed, keyQueueRequeued, keyQueueDL, keyQueueProcessingQueues, keyQueueConsumers, keyConsumerQueues, keyQueueProperties);
|
|
50
44
|
exports.processingQueue.fetchProcessingQueueMessage(redisClient, keyQueueProcessing, (err, message) => {
|
|
51
45
|
if (err)
|
|
52
|
-
done(err);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const { keyMessage } = redis_keys_js_1.redisKeys.getMessageKeys(messageId);
|
|
58
|
-
keys.push(keyMessage);
|
|
59
|
-
const unknowledgementAction = getMessageUnknowledgementAction(message, unknowledgmentReason);
|
|
60
|
-
const { action } = unknowledgementAction;
|
|
61
|
-
const messageStatus = action === index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
62
|
-
? index_js_2.EMessagePropertyStatus.DEAD_LETTERED
|
|
63
|
-
: action === index_js_4.EMessageUnknowledgmentAction.REQUEUE
|
|
64
|
-
? index_js_2.EMessagePropertyStatus.UNACK_REQUEUING
|
|
65
|
-
: index_js_2.EMessagePropertyStatus.UNACK_DELAYING;
|
|
66
|
-
args.push(action, action === index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
67
|
-
? unknowledgementAction.deadLetterReason
|
|
68
|
-
: '', unknowledgmentReason, messageStatus);
|
|
69
|
-
unacknowledgementStatus[messageId] = unknowledgementAction;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
keys.push('');
|
|
73
|
-
args.push('', '', '', unknowledgmentReason, '');
|
|
74
|
-
}
|
|
75
|
-
done();
|
|
46
|
+
return done(err);
|
|
47
|
+
if (!message) {
|
|
48
|
+
keys.push('');
|
|
49
|
+
args.push('', '', '', unknowledgmentReason, '');
|
|
50
|
+
return done();
|
|
76
51
|
}
|
|
52
|
+
const messageId = message.getId();
|
|
53
|
+
const { keyMessage } = redis_keys_js_1.redisKeys.getMessageKeys(messageId);
|
|
54
|
+
keys.push(keyMessage);
|
|
55
|
+
args.push(messageId);
|
|
56
|
+
const unknowledgementAction = getMessageUnknowledgementAction(message, unknowledgmentReason);
|
|
57
|
+
const { action } = unknowledgementAction;
|
|
58
|
+
const messageStatus = action === index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
59
|
+
? index_js_2.EMessagePropertyStatus.DEAD_LETTERED
|
|
60
|
+
: action === index_js_4.EMessageUnknowledgmentAction.REQUEUE
|
|
61
|
+
? index_js_2.EMessagePropertyStatus.UNACK_REQUEUING
|
|
62
|
+
: index_js_2.EMessagePropertyStatus.UNACK_DELAYING;
|
|
63
|
+
args.push(action, action === index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
64
|
+
? unknowledgementAction.deadLetterReason
|
|
65
|
+
: '', unknowledgmentReason, messageStatus);
|
|
66
|
+
unacknowledgementStatus[messageId] = unknowledgementAction;
|
|
67
|
+
done();
|
|
77
68
|
});
|
|
78
69
|
}
|
|
79
70
|
exports.processingQueue = {
|
|
@@ -93,53 +84,58 @@ exports.processingQueue = {
|
|
|
93
84
|
];
|
|
94
85
|
const messageHandlingStatus = {};
|
|
95
86
|
redis_smq_common_1.async.waterfall([
|
|
96
|
-
(
|
|
97
|
-
if (queues === null)
|
|
98
|
-
consumer_queues_js_1.consumerQueues.getConsumerQueues(redisClient, consumerId,
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
(next) => {
|
|
88
|
+
if (queues === null) {
|
|
89
|
+
consumer_queues_js_1.consumerQueues.getConsumerQueues(redisClient, consumerId, next);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
next(null, queues);
|
|
93
|
+
}
|
|
101
94
|
},
|
|
102
|
-
(queueParams,
|
|
103
|
-
if (queueParams.length) {
|
|
104
|
-
|
|
105
|
-
unknowledgeProcessingQueueMessage(redisClient, consumerId, queue, unknowledgmentReason, keys, args, messageHandlingStatus, done);
|
|
106
|
-
}, cb);
|
|
95
|
+
(queueParams, next) => {
|
|
96
|
+
if (!queueParams.length) {
|
|
97
|
+
return next();
|
|
107
98
|
}
|
|
108
|
-
|
|
109
|
-
|
|
99
|
+
redis_smq_common_1.async.eachOf(queueParams, (queue, _, done) => {
|
|
100
|
+
unknowledgeProcessingQueueMessage(redisClient, consumerId, queue, unknowledgmentReason, keys, args, messageHandlingStatus, done);
|
|
101
|
+
}, next);
|
|
110
102
|
},
|
|
111
103
|
], (err) => {
|
|
112
|
-
if (err)
|
|
113
|
-
cb(err);
|
|
114
|
-
else if (keys.length) {
|
|
115
|
-
redisClient.runScript(scripts_js_1.ELuaScriptName.HANDLE_PROCESSING_QUEUE, keys, args, (err, reply) => {
|
|
116
|
-
if (err)
|
|
117
|
-
cb(err);
|
|
118
|
-
else if (reply !== 'OK')
|
|
119
|
-
cb(new index_js_3.ConsumerError(reply ? String(reply) : undefined));
|
|
120
|
-
else {
|
|
121
|
-
for (const messageId in messageHandlingStatus) {
|
|
122
|
-
logger.debug(`Message ID ${messageId} has been ${messageHandlingStatus[messageId].action ===
|
|
123
|
-
index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
124
|
-
? 'dead-lettered'
|
|
125
|
-
: 'unacknowledged'}.`);
|
|
126
|
-
}
|
|
127
|
-
cb(null, messageHandlingStatus);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
104
|
+
if (err) {
|
|
105
|
+
return cb(err);
|
|
130
106
|
}
|
|
131
|
-
|
|
132
|
-
cb();
|
|
107
|
+
if (!keys.length) {
|
|
108
|
+
return cb();
|
|
109
|
+
}
|
|
110
|
+
redisClient.runScript(scripts_js_1.ELuaScriptName.HANDLE_PROCESSING_QUEUE, keys, args, (err, reply) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
return cb(err);
|
|
113
|
+
}
|
|
114
|
+
if (reply !== 'OK') {
|
|
115
|
+
return cb(new index_js_3.ConsumerError(reply ? String(reply) : undefined));
|
|
116
|
+
}
|
|
117
|
+
Object.keys(messageHandlingStatus).forEach((messageId) => {
|
|
118
|
+
const action = messageHandlingStatus[messageId].action ===
|
|
119
|
+
index_js_4.EMessageUnknowledgmentAction.DEAD_LETTER
|
|
120
|
+
? 'dead-lettered'
|
|
121
|
+
: 'unacknowledged';
|
|
122
|
+
logger.debug(`Message ID ${messageId} has been ${action}.`);
|
|
123
|
+
});
|
|
124
|
+
cb(null, messageHandlingStatus);
|
|
125
|
+
});
|
|
133
126
|
});
|
|
134
127
|
},
|
|
135
128
|
fetchProcessingQueueMessage(redisClient, keyQueueProcessing, cb) {
|
|
136
129
|
redisClient.lrange(keyQueueProcessing, 0, 0, (err, range) => {
|
|
137
|
-
if (err)
|
|
138
|
-
cb(err);
|
|
139
|
-
|
|
130
|
+
if (err) {
|
|
131
|
+
return cb(err);
|
|
132
|
+
}
|
|
133
|
+
if (range && range.length) {
|
|
140
134
|
(0, _get_message_js_1._getMessage)(redisClient, range[0], cb);
|
|
141
|
-
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
142
137
|
cb();
|
|
138
|
+
}
|
|
143
139
|
});
|
|
144
140
|
},
|
|
145
141
|
getQueueProcessingQueues(redisClient, queue, cb) {
|