@imqueue/core 1.15.0 → 2.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/index.d.ts CHANGED
@@ -1,19 +1,25 @@
1
1
  /*!
2
2
  * Message Queue factory for @imqueue/core
3
3
  *
4
- * Copyright (c) 2018, imqueue.com <support@imqueue.com>
4
+ * I'm Queue Software Project
5
+ * Copyright (C) 2025 imqueue.com <support@imqueue.com>
5
6
  *
6
- * Permission to use, copy, modify, and/or distribute this software for any
7
- * purpose with or without fee is hereby granted, provided that the above
8
- * copyright notice and this permission notice appear in all copies.
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
9
11
  *
10
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
- * PERFORMANCE OF THIS SOFTWARE.
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ *
20
+ * If you want to use this code in a closed source (commercial) project, you can
21
+ * purchase a proprietary commercial license. Please contact us at
22
+ * <support@imqueue.com> to get commercial licensing options.
17
23
  */
18
24
  import 'reflect-metadata';
19
25
  import { IMessageQueue, IMQMode, IMQOptions } from './src';
package/index.js CHANGED
@@ -17,19 +17,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /*!
18
18
  * Message Queue factory for @imqueue/core
19
19
  *
20
- * Copyright (c) 2018, imqueue.com <support@imqueue.com>
20
+ * I'm Queue Software Project
21
+ * Copyright (C) 2025 imqueue.com <support@imqueue.com>
21
22
  *
22
- * Permission to use, copy, modify, and/or distribute this software for any
23
- * purpose with or without fee is hereby granted, provided that the above
24
- * copyright notice and this permission notice appear in all copies.
23
+ * This program is free software: you can redistribute it and/or modify
24
+ * it under the terms of the GNU General Public License as published by
25
+ * the Free Software Foundation, either version 3 of the License, or
26
+ * (at your option) any later version.
25
27
  *
26
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- * PERFORMANCE OF THIS SOFTWARE.
28
+ * This program is distributed in the hope that it will be useful,
29
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
+ * GNU General Public License for more details.
32
+ *
33
+ * You should have received a copy of the GNU General Public License
34
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
35
+ *
36
+ * If you want to use this code in a closed source (commercial) project, you can
37
+ * purchase a proprietary commercial license. Please contact us at
38
+ * <support@imqueue.com> to get commercial licensing options.
33
39
  */
34
40
  require("reflect-metadata");
35
41
  const src_1 = require("./src");
@@ -49,7 +55,7 @@ class IMQ {
49
55
  static create(name, options = {}, mode = src_1.IMQMode.BOTH) {
50
56
  options = Object.assign({}, IMQ.options, options);
51
57
  let ClassName = `${options.vendor}Queue`;
52
- if (options.cluster) {
58
+ if (options.cluster || options.clusterManagers) {
53
59
  ClassName = `Clustered${ClassName}`;
54
60
  }
55
61
  const Adapter = require(`${__dirname}/src/${ClassName}.js`)[ClassName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imqueue/core",
3
- "version": "1.15.0",
3
+ "version": "2.0.0",
4
4
  "description": "Simple JSON-based messaging queue for inter service communication",
5
5
  "keywords": [
6
6
  "message-queue",
@@ -35,39 +35,38 @@
35
35
  },
36
36
  "homepage": "https://imqueue.com/",
37
37
  "author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
38
- "license": "ISC",
38
+ "license": "GPL-3.0-only",
39
39
  "dependencies": {
40
- "@types/redis": "^2.8.32",
41
- "redis": "3.1.2"
40
+ "ioredis": "^5.6.1"
42
41
  },
43
42
  "devDependencies": {
44
- "@eslint/js": "^9.14.0",
45
- "@types/chai": "^5.0.1",
43
+ "@eslint/js": "^9.30.0",
44
+ "@types/chai": "^5.2.2",
46
45
  "@types/eslint__eslintrc": "^2.1.2",
47
- "@types/mocha": "^10.0.9",
46
+ "@types/mocha": "^10.0.0",
48
47
  "@types/mock-require": "^3.0.0",
49
- "@types/node": "^22.9.0",
50
- "@types/sinon": "^17.0.3",
48
+ "@types/node": "^24.0.8",
49
+ "@types/sinon": "^17.0.4",
51
50
  "@types/yargs": "^17.0.33",
52
- "@typescript-eslint/eslint-plugin": "^8.13.0",
53
- "@typescript-eslint/parser": "^8.13.0",
54
- "@typescript-eslint/typescript-estree": "^8.13.0",
55
- "chai": "^4.3.10",
51
+ "@typescript-eslint/eslint-plugin": "^8.35.1",
52
+ "@typescript-eslint/parser": "^8.35.1",
53
+ "@typescript-eslint/typescript-estree": "^8.35.1",
54
+ "chai": "^5.2.0",
56
55
  "codeclimate-test-reporter": "^0.5.1",
57
56
  "coveralls-next": "^4.2.1",
58
- "eslint": "^9.14.0",
59
- "eslint-plugin-jsdoc": "^50.4.3",
60
- "mocha": "^10.8.2",
57
+ "eslint": "^9.30.0",
58
+ "eslint-plugin-jsdoc": "^51.3.1",
59
+ "mocha": "^11.7.1",
61
60
  "mocha-lcov-reporter": "^1.3.0",
62
61
  "mock-require": "^3.0.3",
63
62
  "nyc": "^17.1.0",
64
- "open": "^10.1.0",
63
+ "open": "^10.1.2",
65
64
  "reflect-metadata": "^0.2.2",
66
- "sinon": "^19.0.2",
65
+ "sinon": "^21.0.0",
67
66
  "source-map-support": "^0.5.21",
68
67
  "ts-node": "^10.9.2",
69
- "typedoc": "^0.26.11",
70
- "typescript": "^5.6.3",
68
+ "typedoc": "^0.28.7",
69
+ "typescript": "^5.8.3",
71
70
  "yargs": "^17.7.2"
72
71
  },
73
72
  "main": "index.js",
@@ -0,0 +1,34 @@
1
+ /*!
2
+ * Clustered messaging queue over Redis implementation
3
+ *
4
+ * I'm Queue Software Project
5
+ * Copyright (C) 2025 imqueue.com <support@imqueue.com>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ *
20
+ * If you want to use this code in a closed source (commercial) project, you can
21
+ * purchase a proprietary commercial license. Please contact us at
22
+ * <support@imqueue.com> to get commercial licensing options.
23
+ */
24
+ import { IMessageQueueConnection, IServerInput } from './IMessageQueue';
25
+ export interface ICluster {
26
+ add: (server: IServerInput) => void;
27
+ remove: (server: IServerInput) => void;
28
+ find: <T extends IMessageQueueConnection>(server: IServerInput) => T | undefined;
29
+ }
30
+ export declare abstract class ClusterManager {
31
+ protected clusters: ICluster[];
32
+ protected constructor();
33
+ init(cluster: ICluster): void;
34
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClusterManager = void 0;
4
+ class ClusterManager {
5
+ constructor() {
6
+ this.clusters = [];
7
+ }
8
+ init(cluster) {
9
+ this.clusters.push(cluster);
10
+ }
11
+ }
12
+ exports.ClusterManager = ClusterManager;
13
+ //# sourceMappingURL=ClusterManager.js.map
@@ -1,29 +1,34 @@
1
- /// <reference types="node" />
2
1
  /*!
3
2
  * Clustered messaging queue over Redis implementation
4
3
  *
5
- * Copyright (c) 2018, imqueue.com <support@imqueue.com>
4
+ * I'm Queue Software Project
5
+ * Copyright (C) 2025 imqueue.com <support@imqueue.com>
6
6
  *
7
- * Permission to use, copy, modify, and/or distribute this software for any
8
- * purpose with or without fee is hereby granted, provided that the above
9
- * copyright notice and this permission notice appear in all copies.
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
10
11
  *
11
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- * PERFORMANCE OF THIS SOFTWARE.
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ *
20
+ * If you want to use this code in a closed source (commercial) project, you can
21
+ * purchase a proprietary commercial license. Please contact us at
22
+ * <support@imqueue.com> to get commercial licensing options.
18
23
  */
19
24
  import { EventEmitter } from 'events';
20
- import { ILogger, IMessageQueue, IMQMode, IMQOptions, JsonObject } from '.';
25
+ import { ILogger, IMessageQueue, IMQMode, IMQOptions, JsonObject, EventMap, IServerInput } from '.';
21
26
  /**
22
27
  * Class ClusteredRedisQueue
23
- * Implements possibility to scale queues horizontally between several
28
+ * Implements the possibility to scale queues horizontally between several
24
29
  * redis instances.
25
30
  */
26
- export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter {
31
+ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<EventMap> {
27
32
  name: string;
28
33
  /**
29
34
  * Logger instance associated with this queue instance
@@ -47,15 +52,15 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter
47
52
  * Part of options without cluster definitions - which are generic for
48
53
  * RedisQueue instances
49
54
  *
50
- * @type {IMQOptions]
55
+ * @type {IMQOptions}
51
56
  */
52
57
  private readonly mqOptions;
53
58
  /**
54
59
  * Cluster servers option definitions
55
60
  *
56
- * @type {{ host: string, port: number }[]}
61
+ * @type {IMessageQueueConnection[]}
57
62
  */
58
- private readonly servers;
63
+ private servers;
59
64
  /**
60
65
  * Current queue index (round-robin)
61
66
  *
@@ -68,13 +73,28 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter
68
73
  * @type {number}
69
74
  */
70
75
  private queueLength;
76
+ /**
77
+ * Template EventEmitter instance used to replicate queue EventEmitters when
78
+ * dynamically modifying the cluster
79
+ * @type {EventEmitter}
80
+ * @private
81
+ */
82
+ private readonly templateEmitter;
83
+ /**
84
+ * Cluster EventEmitter instance used to notify about changes of
85
+ * cluster servers
86
+ * @type {EventEmitter}
87
+ * @private
88
+ */
89
+ private readonly clusterEmitter;
90
+ private state;
71
91
  /**
72
92
  * Class constructor
73
93
  *
74
94
  * @constructor
75
95
  * @param {string} name
76
96
  * @param {Partial<IMQOptions>} options
77
- * @param {IMQMode} mode
97
+ * @param {IMQMode} [mode]
78
98
  */
79
99
  constructor(name: string, options?: Partial<IMQOptions>, mode?: IMQMode);
80
100
  /**
@@ -85,7 +105,7 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter
85
105
  */
86
106
  start(): Promise<ClusteredRedisQueue>;
87
107
  /**
88
- * Stops the queue (should stop handle queue messages).
108
+ * Stops the queue (should stop handling queue messages).
89
109
  * Supposed to be an async function.
90
110
  *
91
111
  * @returns {Promise<ClusteredRedisQueue>}
@@ -97,8 +117,8 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter
97
117
  *
98
118
  * @param {string} toQueue - queue name to which message should be sent to
99
119
  * @param {JsonObject} message - message data
100
- * @param {number} [delay] - if specified, message will be handled in the
101
- * target queue after specified period of time in milliseconds.
120
+ * @param {number} [delay] - if specified, a message will be handled in the
121
+ * target queue after a specified period of time in milliseconds.
102
122
  * @param {(err: Error) => void} [errorHandler] - callback called only when
103
123
  * internal error occurs during message send execution.
104
124
  * @returns {Promise<string>} - message identifier
@@ -146,4 +166,23 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter
146
166
  publish(data: JsonObject, toName?: string): Promise<void>;
147
167
  subscribe(channel: string, handler: (data: JsonObject) => any): Promise<void>;
148
168
  unsubscribe(): Promise<void>;
169
+ /**
170
+ * Adds new servers to the cluster
171
+ *
172
+ * @param {IServerInput} server
173
+ * @returns {void}
174
+ */
175
+ protected addServer(server: IServerInput): void;
176
+ /**
177
+ * Removes server from the cluster
178
+ *
179
+ * @param {IServerInput} server
180
+ * @returns {void}
181
+ */
182
+ protected removeServer(server: IServerInput): void;
183
+ private addServerWithQueueInitializing;
184
+ private eventEmitters;
185
+ private initializeQueue;
186
+ private findServer;
187
+ private static matchServers;
149
188
  }