@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.
Files changed (49) hide show
  1. package/.oxfmtrc.json +9 -0
  2. package/.oxlintrc.json +20 -0
  3. package/README.md +73 -63
  4. package/debug_getter.d.ts +1 -9
  5. package/index.d.ts +0 -1
  6. package/index.js +8 -9
  7. package/package.json +20 -67
  8. package/scripts/strip-comment-coverage.mjs +397 -0
  9. package/src/ClusterManager.d.ts +12 -3
  10. package/src/ClusterManager.js +21 -10
  11. package/src/ClusteredRedisQueue.d.ts +46 -14
  12. package/src/ClusteredRedisQueue.js +196 -169
  13. package/src/IMessageQueue.d.ts +89 -96
  14. package/src/IMessageQueue.js +2 -2
  15. package/src/RedisQueue.d.ts +193 -97
  16. package/src/RedisQueue.js +1328 -1070
  17. package/src/UDPClusterManager.d.ts +110 -26
  18. package/src/UDPClusterManager.js +227 -70
  19. package/src/UDPWorker.d.ts +53 -1
  20. package/src/UDPWorker.js +87 -46
  21. package/src/{promisify.d.ts → helpers/buildOptions.d.ts} +8 -15
  22. package/src/helpers/buildOptions.js +39 -0
  23. package/src/{copyEventEmitter.d.ts → helpers/copyEventEmitter.d.ts} +1 -1
  24. package/src/{copyEventEmitter.js → helpers/copyEventEmitter.js} +3 -4
  25. package/src/helpers/envInt.d.ts +32 -0
  26. package/src/helpers/envInt.js +39 -0
  27. package/src/helpers/escapeRegExp.d.ts +30 -0
  28. package/src/helpers/escapeRegExp.js +36 -0
  29. package/src/helpers/index.d.ts +31 -0
  30. package/src/helpers/index.js +48 -0
  31. package/src/helpers/pack.d.ts +7 -0
  32. package/src/helpers/pack.js +37 -0
  33. package/src/helpers/randomInt.d.ts +31 -0
  34. package/src/helpers/randomInt.js +37 -0
  35. package/src/helpers/sha1.d.ts +7 -0
  36. package/src/helpers/sha1.js +39 -0
  37. package/src/helpers/unpack.d.ts +7 -0
  38. package/src/helpers/unpack.js +37 -0
  39. package/src/index.d.ts +1 -14
  40. package/src/index.js +1 -19
  41. package/src/profile.d.ts +28 -38
  42. package/src/profile.js +100 -95
  43. package/src/redis.d.ts +1 -1
  44. package/src/redis.js +4 -2
  45. package/typedoc.json +19 -0
  46. package/eslint.config.mjs +0 -98
  47. package/src/promisify.js +0 -106
  48. package/src/uuid.d.ts +0 -6
  49. package/src/uuid.js +0 -65
package/.oxfmtrc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "singleQuote": true,
3
+ "tabWidth": 4,
4
+ "printWidth": 80,
5
+ "semi": true,
6
+ "trailingComma": "all",
7
+ "arrowParens": "avoid",
8
+ "bracketSpacing": true
9
+ }
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
  [![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://rawgit.com/imqueue/core/master/LICENSE)
4
4
 
5
- Simple JSON-based messaging queue for inter service communication
5
+ Simple JSON-based messaging queue for inter-service communication
6
6
 
7
7
  **Related packages:**
8
8
 
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.
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
- - **Fast unwarranted** message delivery (if consumer grab the message and dies
19
- message will be lost). Up to ~35-40k of 1Kb messages per second on i7 core by
20
- benchmarks.
21
- - **Fast warranted** message delivery (only 1.5-2 times slower than
22
- unwarranted). If consumer grab a message and dies it will be re-scheduled
23
- in queue. Up to ~20-25K of 1Kb messages per second on i7 core by benchmarks.
24
- - **No timers or constant redis polling** used for implementation, as result -
25
- no delays in delivery and low CPU usage on application workers. When idling
26
- it does not consume resources!
27
- - **Supports gzip compression for messages** (decrease traffic usage, but
28
- slower).
29
- - **Concurrent workers model supported**, the same queue can have multiple
30
- consumers.
31
- - **Delayed messages supported**, fast as ~10K of 1Kb messages per second on i7
32
- core by benchmarks.
33
- - **Safe predictable scaling of queues**. Scaling number of workers does not
34
- influence traffic usage.
35
- - **Round-robin message balancing between several redis instances**. This
36
- allows easy messaging queue redis horizontal scaling.
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 have only one available adapter which is Redis server
42
- related. So redis-server > 3.8+ is required.
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 redis it will be required to turn on manually
45
- keyspace notification events (actual on use with ElasticCache on AWS), like:
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
- Further, more adapters will be added... if needed.
51
+ More adapters will be added in the future as needed.
52
52
 
53
53
  # Install
54
54
 
55
- ~~~bash
55
+ ```bash
56
56
  npm i --save @imqueue/core
57
- ~~~
57
+ ```
58
58
 
59
59
  # Usage
60
60
 
61
- ~~~typescript
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 of all make sure redis-server is running on the localhost. Current
98
- version of benchmark supposed to have redis running localhost because
99
- it is going to measure it's CPU usage stats.
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 their dedicated CPU affinity
102
- to make sure collected stats as accurate as possible.
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
- ~~~bash
105
- git clone git@github.com:Mikhus/core.git
106
- cd imq
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
- Number of child workers running message queues are limited to a max number
134
- of CPU in the system -2. First one, which is CPU0 is reserved for OS tasks and
135
- for stats collector process. Second, which is CPU1 is dedicated to redis
136
- process running on a local machine, All others are safe to run queue workers.
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, if there is 8 cores on a machine it is safe to run up to 6 workers.
139
- For 4-core machine this number is limited to 2.
140
- If there is less cores results will not give good visibility of load.
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
- *NOTE: paragraphs above this note are Linux-only related! On MacOS
143
- there is no good way to set process affinity to a CPU core, Windows support is
144
- not tested and is missing for the moment in benchmarking. I does not mean
145
- benchmark will not work on Mac & Win but the results won't be accurate and
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
- ~~~bash
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 imq
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
@@ -1,9 +1 @@
1
- declare class DebugGetter {
2
- name: string;
3
- static propertiesMap: Record<string, string>;
4
- private get property();
5
- private set property(value);
6
- constructor(name: string);
7
- addProperty(value: string): void;
8
- removeProperty(): void;
9
- }
1
+ export {};
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": "2.0.25",
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
- "prepare": "./node_modules/.bin/tsc",
16
- "test": "./node_modules/.bin/tsc && ./node_modules/.bin/nyc mocha --exit --timeout 10000 && ./node_modules/.bin/nyc report --reporter=text-lcov",
17
- "test-fast": "./node_modules/.bin/tsc && ./node_modules/.bin/nyc mocha --exit --timeout 10000 && /usr/bin/env node -e \"import('open').then(open => open.default('file://`pwd`/coverage/index.html', { wait: false }))\"",
18
- "test-local": "export COVERALLS_REPO_TOKEN=$IMQ_COVERALLS_TOKEN && npm test && /usr/bin/env node -e \"import('open').then(open => open.default('https://coveralls.io/github/imqueue/imq', { wait: false }))\"",
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": "rm -rf docs && typedoc --excludePrivate --excludeExternals --hideGenerator --exclude \"**/+(test|node_modules|docs|coverage|benchmark|.nyc_output)/**/*\" --out ./docs . && /usr/bin/env node -e \"import('open').then(open => open.default('file://`pwd`/docs/index.html',{wait:false}))\""
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.8.2"
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.2.1",
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
- "nyc": "^17.1.0",
63
- "open": "^10.2.0",
64
- "reflect-metadata": "^0.2.2",
65
- "sinon": "^21.0.0",
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
- "typescript": {
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
  }