@imqueue/core 2.0.25 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.oxfmtrc.json +9 -0
- package/.oxlintrc.json +20 -0
- package/README.md +73 -63
- package/debug_getter.d.ts +1 -9
- package/index.d.ts +0 -1
- package/index.js +8 -9
- package/package.json +20 -67
- package/scripts/strip-comment-coverage.mjs +397 -0
- package/src/ClusterManager.d.ts +12 -3
- package/src/ClusterManager.js +21 -10
- package/src/ClusteredRedisQueue.d.ts +46 -14
- package/src/ClusteredRedisQueue.js +196 -169
- package/src/IMessageQueue.d.ts +89 -96
- package/src/IMessageQueue.js +2 -2
- package/src/RedisQueue.d.ts +193 -97
- package/src/RedisQueue.js +1328 -1070
- package/src/UDPClusterManager.d.ts +110 -26
- package/src/UDPClusterManager.js +227 -70
- package/src/UDPWorker.d.ts +53 -1
- package/src/UDPWorker.js +87 -46
- package/src/{promisify.d.ts → helpers/buildOptions.d.ts} +8 -15
- package/src/helpers/buildOptions.js +39 -0
- package/src/{copyEventEmitter.d.ts → helpers/copyEventEmitter.d.ts} +1 -1
- package/src/{copyEventEmitter.js → helpers/copyEventEmitter.js} +3 -4
- package/src/helpers/envInt.d.ts +32 -0
- package/src/helpers/envInt.js +39 -0
- package/src/helpers/escapeRegExp.d.ts +30 -0
- package/src/helpers/escapeRegExp.js +36 -0
- package/src/helpers/index.d.ts +31 -0
- package/src/helpers/index.js +48 -0
- package/src/helpers/pack.d.ts +7 -0
- package/src/helpers/pack.js +37 -0
- package/src/helpers/randomInt.d.ts +31 -0
- package/src/helpers/randomInt.js +37 -0
- package/src/helpers/sha1.d.ts +7 -0
- package/src/helpers/sha1.js +39 -0
- package/src/helpers/unpack.d.ts +7 -0
- package/src/helpers/unpack.js +37 -0
- package/src/index.d.ts +1 -14
- package/src/index.js +1 -19
- package/src/profile.d.ts +28 -38
- package/src/profile.js +100 -95
- package/src/redis.d.ts +1 -1
- package/src/redis.js +4 -2
- package/typedoc.json +19 -0
- package/eslint.config.mjs +0 -98
- package/src/promisify.js +0 -106
- package/src/uuid.d.ts +0 -6
- package/src/uuid.js +0 -65
package/.oxfmtrc.json
ADDED
package/.oxlintrc.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"categories": {
|
|
4
|
+
"correctness": "error"
|
|
5
|
+
},
|
|
6
|
+
"rules": {
|
|
7
|
+
"no-debugger": "error",
|
|
8
|
+
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
|
|
9
|
+
"no-unused-vars": "warn"
|
|
10
|
+
},
|
|
11
|
+
"ignorePatterns": [
|
|
12
|
+
"**/*.js",
|
|
13
|
+
"**/*.d.ts",
|
|
14
|
+
"docs/",
|
|
15
|
+
"coverage/",
|
|
16
|
+
".nyc_output/",
|
|
17
|
+
".agent-out/",
|
|
18
|
+
"node_modules/"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/README.md
CHANGED
|
@@ -2,63 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://rawgit.com/imqueue/core/master/LICENSE)
|
|
4
4
|
|
|
5
|
-
Simple JSON-based messaging queue for inter
|
|
5
|
+
Simple JSON-based messaging queue for inter-service communication
|
|
6
6
|
|
|
7
7
|
**Related packages:**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
- [@imqueue/rpc](https://github.com/imqueue/rpc) - RPC-like client/service
|
|
10
|
+
implementation over @imqueue/core.
|
|
11
|
+
- [@imqueue/cli](https://github.com/imqueue/cli) - Command Line Interface
|
|
12
|
+
for imqueue.
|
|
13
13
|
|
|
14
14
|
# Features
|
|
15
15
|
|
|
16
16
|
With current implementation on RedisQueue:
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- **TypeScript included!**
|
|
18
|
+
- **Fast, unreliable** message delivery (if a consumer grabs the message and dies,
|
|
19
|
+
the message will be lost). Up to ~35–40k of 1Kb messages per second on an i7 core
|
|
20
|
+
by benchmarks.
|
|
21
|
+
- **Fast, guaranteed** message delivery (only 1.5–2 times slower than
|
|
22
|
+
unreliable mode). If a consumer grabs a message and dies, it will be rescheduled
|
|
23
|
+
to the queue. Up to ~20–25k of 1Kb messages per second on an i7 core by benchmarks.
|
|
24
|
+
- **No timers or constant Redis polling** used for implementation, resulting in
|
|
25
|
+
no delays in delivery and low CPU usage on application workers. When idle,
|
|
26
|
+
it consumes no resources.
|
|
27
|
+
- **Supports Gzip compression for messages** (decreases traffic usage but is slower).
|
|
28
|
+
- **Concurrent workers model supported**, the same queue can have multiple
|
|
29
|
+
consumers.
|
|
30
|
+
- **Delayed messages supported**, fast as ~10K of 1Kb messages per second on i7
|
|
31
|
+
core by benchmarks.
|
|
32
|
+
- **Safe, predictable scaling of queues**. Scaling the number of workers does not
|
|
33
|
+
increase traffic usage.
|
|
34
|
+
- **Round-robin message balancing between multiple Redis instances**. This
|
|
35
|
+
allows easy horizontal scaling of the messaging queue across Redis instances.
|
|
36
|
+
- **TypeScript included!**
|
|
38
37
|
|
|
39
38
|
# Requirements
|
|
40
39
|
|
|
41
|
-
Currently this module
|
|
42
|
-
|
|
40
|
+
Currently this module has only one available adapter, which is Redis. Redis server
|
|
41
|
+
6.2+ is required (the queue relies on `LMOVE`/`BLMOVE` commands for safe message
|
|
42
|
+
delivery).
|
|
43
43
|
|
|
44
|
-
If config command is disabled on
|
|
45
|
-
|
|
44
|
+
If the config command is disabled on Redis, you must manually enable keyspace
|
|
45
|
+
notification events (particularly when using AWS ElasticCache), like this:
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
```
|
|
48
48
|
notify-keyspace-events Ex
|
|
49
|
-
|
|
49
|
+
```
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
More adapters will be added in the future as needed.
|
|
52
52
|
|
|
53
53
|
# Install
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
```bash
|
|
56
56
|
npm i --save @imqueue/core
|
|
57
|
-
|
|
57
|
+
```
|
|
58
58
|
|
|
59
59
|
# Usage
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
```typescript
|
|
62
62
|
import IMQ, { IMessageQueue, IJson } from '@imqueue/core';
|
|
63
63
|
|
|
64
64
|
(async () => {
|
|
@@ -90,27 +90,27 @@ import IMQ, { IMessageQueue, IJson } from '@imqueue/core';
|
|
|
90
90
|
const delay = 1000;
|
|
91
91
|
await queueOne.send('QueueOne', { delay }, delay);
|
|
92
92
|
})();
|
|
93
|
-
|
|
93
|
+
```
|
|
94
94
|
|
|
95
95
|
# Benchmarking
|
|
96
96
|
|
|
97
|
-
First
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
First, make sure redis-server is running on localhost. The current version of the
|
|
98
|
+
benchmark requires Redis to be running on localhost so it can measure its CPU
|
|
99
|
+
usage statistics.
|
|
100
100
|
|
|
101
|
-
All workers during benchmark test will have
|
|
102
|
-
|
|
101
|
+
All workers during the benchmark test will have dedicated CPU affinity to ensure
|
|
102
|
+
the collected statistics are as accurate as possible.
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
git clone git@github.com:
|
|
106
|
-
cd
|
|
104
|
+
```bash
|
|
105
|
+
git clone git@github.com:imqueue/core.git
|
|
106
|
+
cd core
|
|
107
107
|
node benchmark -c 4 -m 10000
|
|
108
|
-
|
|
108
|
+
```
|
|
109
109
|
|
|
110
110
|
Other possible benchmark options:
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
node benchmark -h
|
|
112
|
+
```
|
|
113
|
+
node benchmark -h
|
|
114
114
|
Options:
|
|
115
115
|
--version Show version number [boolean]
|
|
116
116
|
-h, --help Show help [boolean]
|
|
@@ -128,30 +128,40 @@ Options:
|
|
|
128
128
|
-p, --port Redis server port to connect to.
|
|
129
129
|
-t, --message-multiply-times Increase sample message data given number of
|
|
130
130
|
times.
|
|
131
|
-
|
|
131
|
+
```
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
The number of child workers running message queues is limited to the number of CPUs
|
|
134
|
+
in the system minus 2. The first CPU (CPU0) is reserved for OS tasks and the stats
|
|
135
|
+
collector process. The second CPU (CPU1) is dedicated to the local Redis process.
|
|
136
|
+
All others are available to run queue workers.
|
|
137
137
|
|
|
138
|
-
For example,
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
For example, on an 8-core machine you can safely run up to 6 workers. On a 4-core
|
|
139
|
+
machine, this limit is 2 workers. If there are fewer cores, the results will not
|
|
140
|
+
provide good visibility of the load.
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
predictable.*
|
|
142
|
+
**NOTE:** The paragraphs above apply to Linux only. On macOS there is no reliable way
|
|
143
|
+
to set process CPU affinity, and Windows support is not currently implemented for
|
|
144
|
+
benchmarking. This does not mean the benchmark won't work on macOS or Windows, but
|
|
145
|
+
the results will not be accurate or predictable on those platforms.
|
|
147
146
|
|
|
148
147
|
## Running Unit Tests
|
|
149
148
|
|
|
150
|
-
|
|
149
|
+
Tests run on the native Node.js test runner (`node:test`) with `node:assert` and
|
|
150
|
+
no external test framework, so a plain clone and install is all that is needed:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
151
153
|
git clone git@github.com:imqueue/core.git
|
|
152
|
-
cd
|
|
154
|
+
cd core
|
|
155
|
+
npm install
|
|
153
156
|
npm test
|
|
154
|
-
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
To produce a coverage report use:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
npm run test-coverage # prints coverage summary to the console
|
|
163
|
+
npm run test-lcov # writes coverage/lcov.info
|
|
164
|
+
```
|
|
155
165
|
|
|
156
166
|
## License
|
|
157
167
|
|
package/debug_getter.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
* purchase a proprietary commercial license. Please contact us at
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
|
-
import 'reflect-metadata';
|
|
25
24
|
import { IMessageQueue, IMQMode, IMQOptions } from './src';
|
|
26
25
|
export * from './src';
|
|
27
26
|
/**
|
package/index.js
CHANGED
|
@@ -37,13 +37,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
* purchase a proprietary commercial license. Please contact us at
|
|
38
38
|
* <support@imqueue.com> to get commercial licensing options.
|
|
39
39
|
*/
|
|
40
|
-
require("reflect-metadata");
|
|
41
40
|
const src_1 = require("./src");
|
|
42
41
|
__exportStar(require("./src"), exports);
|
|
43
42
|
/**
|
|
44
43
|
* Message Queue Factory
|
|
45
44
|
*/
|
|
46
45
|
class IMQ {
|
|
46
|
+
/**
|
|
47
|
+
* Base generic queue factory options
|
|
48
|
+
*
|
|
49
|
+
* @type {Partial<IMQOptions>}
|
|
50
|
+
*/
|
|
51
|
+
static options = {
|
|
52
|
+
vendor: 'Redis', // default vendor
|
|
53
|
+
};
|
|
47
54
|
/**
|
|
48
55
|
* Instantiate proper message queue instance using given user-options
|
|
49
56
|
*
|
|
@@ -62,13 +69,5 @@ class IMQ {
|
|
|
62
69
|
return new Adapter(name, options, mode);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Base generic queue factory options
|
|
67
|
-
*
|
|
68
|
-
* @type {Partial<IMQOptions>}
|
|
69
|
-
*/
|
|
70
|
-
IMQ.options = {
|
|
71
|
-
vendor: 'Redis', // default vendor
|
|
72
|
-
};
|
|
73
72
|
exports.default = IMQ;
|
|
74
73
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imqueue/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Simple JSON-based messaging queue for inter service communication",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"message-queue",
|
|
@@ -12,20 +12,25 @@
|
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
14
|
"benchmark": "node benchmark -c $(( $(nproc) - 2 )) -m 100000",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"clean-compiled": "npm run clean-js && npm run clean-typedefs && npm run clean-maps",
|
|
16
|
+
"build": "npm run clean-compiled && tsc",
|
|
17
|
+
"prepare": "npm run build",
|
|
18
|
+
"lint": "oxlint",
|
|
19
|
+
"format": "oxfmt \"index.ts\" \"src/**/*.ts\" \"test/**/*.ts\" \"benchmark/**/*.ts\"",
|
|
20
|
+
"format:check": "oxfmt --check \"index.ts\" \"src/**/*.ts\" \"test/**/*.ts\" \"benchmark/**/*.ts\"",
|
|
21
|
+
"test": "npm run build && node --test --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
22
|
+
"test-coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
23
|
+
"test-lcov": "npm run build && mkdir -p coverage && node --enable-source-maps --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-timeout=15000 $(find test -name '*.spec.js'); node scripts/strip-comment-coverage.mjs coverage/lcov.info",
|
|
24
|
+
"test-coverage-html": "npm run test-lcov; genhtml coverage/lcov.info --output-directory coverage/html --ignore-errors inconsistent,corrupt,format,mismatch && echo \"Coverage report: file://$(pwd)/coverage/html/index.html\"",
|
|
19
25
|
"test-dev": "npm run test && npm run clean-js && npm run clean-typedefs && npm run clean-maps",
|
|
20
|
-
"test-coverage": "cat ./coverage/lcov.info | CODECLIMATE_API_HOST=https://codebeat.co/webhooks/code_coverage CODECLIMATE_REPO_TOKEN=85bb2a18-4ebb-4e48-a2ce-92b7bf438b1a ./node_modules/.bin/codeclimate-test-reporter",
|
|
21
26
|
"clean-typedefs": "find . -name '*.d.ts' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
|
|
22
27
|
"clean-maps": "find . -name '*.js.map' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
|
|
23
28
|
"clean-js": "find . -name '*.js' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
|
|
24
|
-
"clean-tests": "rm -rf .nyc_output coverage",
|
|
29
|
+
"clean-tests": "rm -rf .nyc_output coverage .agent-out",
|
|
25
30
|
"clean-doc": "rm -rf docs",
|
|
26
31
|
"clean-benchmark": "rm -rf benchmark-result",
|
|
27
32
|
"clean": "npm run clean-tests && npm run clean-typedefs && npm run clean-maps && npm run clean-js && npm run clean-doc && npm run clean-benchmark",
|
|
28
|
-
"doc": "
|
|
33
|
+
"doc": "typedoc && echo \"Docs generated: file://$(pwd)/docs/index.html\""
|
|
29
34
|
},
|
|
30
35
|
"repository": {
|
|
31
36
|
"type": "git",
|
|
@@ -38,69 +43,17 @@
|
|
|
38
43
|
"author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
|
|
39
44
|
"license": "GPL-3.0-only",
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"ioredis": "^5.
|
|
46
|
+
"ioredis": "^5.11.1"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {
|
|
44
|
-
"@eslint/js": "^9.33.0",
|
|
45
|
-
"@types/chai": "^5.2.2",
|
|
46
|
-
"@types/eslint__eslintrc": "^2.1.2",
|
|
47
|
-
"@types/mocha": "^10.0.0",
|
|
48
49
|
"@types/mock-require": "^3.0.0",
|
|
49
|
-
"@types/node": "^24.
|
|
50
|
-
"@types/sinon": "^17.0.4",
|
|
51
|
-
"@types/yargs": "^17.0.33",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^8.39.0",
|
|
53
|
-
"@typescript-eslint/parser": "^8.39.0",
|
|
54
|
-
"@typescript-eslint/typescript-estree": "^8.39.0",
|
|
55
|
-
"chai": "^5.2.1",
|
|
56
|
-
"coveralls-next": "^5.0.0",
|
|
57
|
-
"eslint": "^9.33.0",
|
|
58
|
-
"eslint-plugin-jsdoc": "^52.0.4",
|
|
59
|
-
"mocha": "^11.7.1",
|
|
60
|
-
"mocha-lcov-reporter": "^1.3.0",
|
|
50
|
+
"@types/node": "^24.9.1",
|
|
61
51
|
"mock-require": "^3.0.3",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"source-map-support": "^0.5.21",
|
|
67
|
-
"ts-node": "^10.9.2",
|
|
68
|
-
"typedoc": "^0.28.9",
|
|
69
|
-
"typescript": "^5.9.2",
|
|
70
|
-
"yargs": "^18.0.0"
|
|
52
|
+
"oxfmt": "0.57.0",
|
|
53
|
+
"oxlint": "1.72.0",
|
|
54
|
+
"typedoc": "^0.28.20",
|
|
55
|
+
"typescript": "^6.0.3"
|
|
71
56
|
},
|
|
72
57
|
"main": "index.js",
|
|
73
|
-
"
|
|
74
|
-
"definitions": "index.d.ts"
|
|
75
|
-
},
|
|
76
|
-
"mocha": {
|
|
77
|
-
"require": [
|
|
78
|
-
"ts-node/register",
|
|
79
|
-
"source-map-support/register"
|
|
80
|
-
],
|
|
81
|
-
"recursive": true,
|
|
82
|
-
"bail": true,
|
|
83
|
-
"full-trace": true,
|
|
84
|
-
"exit": true,
|
|
85
|
-
"timeout": 10000
|
|
86
|
-
},
|
|
87
|
-
"nyc": {
|
|
88
|
-
"check-coverage": false,
|
|
89
|
-
"extension": [
|
|
90
|
-
".ts"
|
|
91
|
-
],
|
|
92
|
-
"exclude": [
|
|
93
|
-
"**/*.d.ts",
|
|
94
|
-
"**/test/**"
|
|
95
|
-
],
|
|
96
|
-
"require": [
|
|
97
|
-
"ts-node/register"
|
|
98
|
-
],
|
|
99
|
-
"reporter": [
|
|
100
|
-
"html",
|
|
101
|
-
"text",
|
|
102
|
-
"text-summary",
|
|
103
|
-
"lcovonly"
|
|
104
|
-
]
|
|
105
|
-
}
|
|
58
|
+
"types": "index.d.ts"
|
|
106
59
|
}
|