redis-smq 7.0.0-rc.1 → 7.0.0-rc.2
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 +7 -0
- package/dist/misc/health-check/combined-run.d.ts +1 -0
- package/dist/misc/health-check/combined-run.js +45 -0
- package/dist/misc/health-check/on-off.d.ts +1 -0
- package/dist/misc/health-check/on-off.js +58 -0
- package/dist/src/monitor-server/workers/websocket-rate-stream.worker.d.ts +6 -23
- package/dist/src/monitor-server/workers/websocket-rate-stream.worker.js +79 -110
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 7.0.0-rc.2 (2022-05-18)
|
|
4
|
+
|
|
5
|
+
* Fix typo (8002616)
|
|
6
|
+
* Update docs (d40b1c2)
|
|
7
|
+
* Update misc scripts (bde5171)
|
|
8
|
+
* Clean up WebsocketRateStreamWorker, use incremental timestamp (918fac0)
|
|
9
|
+
|
|
3
10
|
## 7.0.0-rc.1 (2022-05-15)
|
|
4
11
|
|
|
5
12
|
* Update docs (41ee4bf)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("../..");
|
|
4
|
+
(0, __1.setConfiguration)({
|
|
5
|
+
logger: {
|
|
6
|
+
enabled: false,
|
|
7
|
+
},
|
|
8
|
+
monitor: {
|
|
9
|
+
enabled: true,
|
|
10
|
+
basePath: '/',
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
store: true,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
(0, __1.setLogger)(console);
|
|
17
|
+
const producer = new __1.Producer();
|
|
18
|
+
const consumer = new __1.Consumer();
|
|
19
|
+
consumer.run();
|
|
20
|
+
const monitorServer = new __1.MonitorServer();
|
|
21
|
+
monitorServer.listen().catch((err) => console.log(err));
|
|
22
|
+
const produce = (err) => {
|
|
23
|
+
if (err)
|
|
24
|
+
console.log(err);
|
|
25
|
+
else {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
const m = new __1.Message().setBody(Date.now()).setQueue(queue);
|
|
28
|
+
producer.produce(m, produce);
|
|
29
|
+
}, 1000);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const queue = `queue_${Date.now()}`;
|
|
33
|
+
__1.QueueManager.getSingletonInstance((err, queueManager) => {
|
|
34
|
+
if (err)
|
|
35
|
+
console.log(err);
|
|
36
|
+
else {
|
|
37
|
+
queueManager === null || queueManager === void 0 ? void 0 : queueManager.queue.create(queue, false, (err) => {
|
|
38
|
+
if (err)
|
|
39
|
+
console.log(err);
|
|
40
|
+
else
|
|
41
|
+
consumer.consume(queue, (msg, cb) => cb(), produce);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=combined-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("../..");
|
|
4
|
+
const events_1 = require("../../src/system/common/events");
|
|
5
|
+
const async_1 = require("../../src/system/lib/async");
|
|
6
|
+
const queue = `queue_${Date.now()}`;
|
|
7
|
+
const producer = new __1.Producer();
|
|
8
|
+
const produceForever = (err) => {
|
|
9
|
+
if (err)
|
|
10
|
+
console.log(err);
|
|
11
|
+
else {
|
|
12
|
+
if (producer.isGoingUp() || producer.isRunning()) {
|
|
13
|
+
const message = new __1.Message().setBody('some data').setQueue(queue);
|
|
14
|
+
producer.produce(message, produceForever);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const consumer = new __1.Consumer();
|
|
19
|
+
consumer.consume(queue, (message, cb) => cb(), (err) => err && console.log(err));
|
|
20
|
+
consumer.on(events_1.events.UP, () => {
|
|
21
|
+
console.log('UP');
|
|
22
|
+
});
|
|
23
|
+
consumer.on(events_1.events.DOWN, () => {
|
|
24
|
+
console.log('DOWN');
|
|
25
|
+
});
|
|
26
|
+
const serialOnOff = (cb) => (0, async_1.waterfall)([
|
|
27
|
+
(cb) => consumer.run((err) => cb(err)),
|
|
28
|
+
(cb) => consumer.shutdown((err) => cb(err)),
|
|
29
|
+
(cb) => consumer.run((err) => cb(err)),
|
|
30
|
+
(cb) => consumer.shutdown((err) => cb(err)),
|
|
31
|
+
(cb) => consumer.run((err) => cb(err)),
|
|
32
|
+
(cb) => consumer.shutdown((err) => cb(err)),
|
|
33
|
+
(cb) => consumer.run((err) => cb(err)),
|
|
34
|
+
(cb) => consumer.shutdown((err) => cb(err)),
|
|
35
|
+
(cb) => consumer.run((err) => cb(err)),
|
|
36
|
+
(cb) => consumer.shutdown((err) => cb(err)),
|
|
37
|
+
], cb);
|
|
38
|
+
(0, async_1.waterfall)([
|
|
39
|
+
(cb) => __1.QueueManager.getSingletonInstance((err, queueManager) => {
|
|
40
|
+
if (err)
|
|
41
|
+
cb(err);
|
|
42
|
+
else
|
|
43
|
+
queueManager === null || queueManager === void 0 ? void 0 : queueManager.queue.create(queue, false, cb);
|
|
44
|
+
}),
|
|
45
|
+
(cb) => {
|
|
46
|
+
produceForever();
|
|
47
|
+
serialOnOff(cb);
|
|
48
|
+
},
|
|
49
|
+
], (err) => {
|
|
50
|
+
if (err)
|
|
51
|
+
console.log(err);
|
|
52
|
+
else {
|
|
53
|
+
producer.shutdown();
|
|
54
|
+
consumer.shutdown();
|
|
55
|
+
__1.QueueManager.getSingletonInstance((err, queueManager) => queueManager === null || queueManager === void 0 ? void 0 : queueManager.quit(() => void 0));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=on-off.js.map
|
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import { ICallback, TQueueParams } from '../../../types';
|
|
2
2
|
import { Worker } from '../../system/common/worker/worker';
|
|
3
3
|
export declare class WebsocketRateStreamWorker extends Worker {
|
|
4
|
-
protected
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
protected tasks: ((cb: ICallback<void>) => void)[];
|
|
12
|
-
protected reset: () => void;
|
|
13
|
-
protected addConsumerTasks: (ts: number, queue: TQueueParams, consumerId: string) => void;
|
|
14
|
-
protected addQueueTasks: (ts: number, queue: TQueueParams) => void;
|
|
15
|
-
protected addGlobalTasks: (ts: number) => void;
|
|
16
|
-
protected addQueue: (queue: TQueueParams) => {
|
|
17
|
-
consumers: string[];
|
|
18
|
-
};
|
|
19
|
-
protected handleQueueConsumers: (ts: number, queue: TQueueParams, consumers: string[], cb: ICallback<void>) => void;
|
|
20
|
-
protected handleQueue: (ts: number, queue: TQueueParams, queueProperties: {
|
|
21
|
-
consumers: string[];
|
|
22
|
-
}, cb: ICallback<void>) => void;
|
|
23
|
-
protected prepare: (cb: ICallback<void>) => void;
|
|
24
|
-
protected publish: (cb: ICallback<void>) => void;
|
|
25
|
-
protected consumersCount: (cb: ICallback<void>) => void;
|
|
26
|
-
protected getQueues: (cb: ICallback<void>) => void;
|
|
4
|
+
protected timestamp: number;
|
|
5
|
+
protected publishConsumerTimeSeries: (queue: TQueueParams, consumerId: string, cb: ICallback<void>) => void;
|
|
6
|
+
protected publishQueueTimeSeries: (queue: TQueueParams, cb: ICallback<void>) => void;
|
|
7
|
+
protected handleGlobalTimeSeries: (cb: ICallback<void>) => void;
|
|
8
|
+
protected handleConsumersTimeSeries: (cb: ICallback<void>) => void;
|
|
9
|
+
protected handleQueuesTimeSeries: (cb: ICallback<void>) => void;
|
|
27
10
|
work: (cb: ICallback<void>) => void;
|
|
28
11
|
}
|
|
29
12
|
export default WebsocketRateStreamWorker;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebsocketRateStreamWorker = void 0;
|
|
4
4
|
const redis_keys_1 = require("../../system/common/redis-keys/redis-keys");
|
|
5
5
|
const consumer_heartbeat_1 = require("../../system/app/consumer/consumer-heartbeat");
|
|
6
|
-
const time_series_1 = require("../../system/common/time-series/time-series");
|
|
7
6
|
const queue_published_time_series_1 = require("../../system/app/producer/producer-time-series/queue-published-time-series");
|
|
8
7
|
const queue_dead_lettered_time_series_1 = require("../../system/app/consumer/consumer-time-series/queue-dead-lettered-time-series");
|
|
9
8
|
const queue_acknowledged_time_series_1 = require("../../system/app/consumer/consumer-time-series/queue-acknowledged-time-series");
|
|
@@ -18,110 +17,76 @@ const async_1 = require("../../system/lib/async");
|
|
|
18
17
|
class WebsocketRateStreamWorker extends worker_1.Worker {
|
|
19
18
|
constructor() {
|
|
20
19
|
super(...arguments);
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
this.timestamp = 0;
|
|
21
|
+
this.publishConsumerTimeSeries = (queue, consumerId, cb) => {
|
|
22
|
+
(0, async_1.waterfall)([
|
|
23
|
+
(cb) => (0, consumer_acknowledged_time_series_1.ConsumerAcknowledgedTimeSeries)(this.redisClient, consumerId).getRangeFrom(this.timestamp, (err, reply) => {
|
|
24
|
+
if (err)
|
|
25
|
+
cb(err);
|
|
26
|
+
else {
|
|
27
|
+
this.redisClient.publish(`streamConsumerAcknowledged:${consumerId}`, JSON.stringify(reply), () => cb());
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
(cb) => (0, consumer_dead_lettered_time_series_1.ConsumerDeadLetteredTimeSeries)(this.redisClient, consumerId).getRangeFrom(this.timestamp, (err, reply) => {
|
|
31
|
+
if (err)
|
|
32
|
+
cb(err);
|
|
33
|
+
else {
|
|
34
|
+
this.redisClient.publish(`streamConsumerDeadLettered:${consumerId}`, JSON.stringify(reply), () => cb());
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
], cb);
|
|
26
38
|
};
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.tasks.push((cb) => (0, queue_dead_lettered_time_series_1.QueueDeadLetteredTimeSeries)(this.redisClient, queue).getRangeFrom(ts, (err, reply) => {
|
|
52
|
-
if (err)
|
|
53
|
-
cb(err);
|
|
54
|
-
else {
|
|
55
|
-
this.redisClient.publish(`streamQueueDeadLettered:${queue.ns}:${queue.name}`, JSON.stringify(reply), () => cb());
|
|
56
|
-
}
|
|
57
|
-
}));
|
|
58
|
-
this.tasks.push((cb) => (0, queue_published_time_series_1.QueuePublishedTimeSeries)(this.redisClient, queue).getRangeFrom(ts, (err, reply) => {
|
|
59
|
-
if (err)
|
|
60
|
-
cb(err);
|
|
61
|
-
else {
|
|
62
|
-
this.redisClient.publish(`streamQueuePublished:${queue.ns}:${queue.name}`, JSON.stringify(reply), () => cb());
|
|
63
|
-
}
|
|
64
|
-
}));
|
|
65
|
-
};
|
|
66
|
-
this.addGlobalTasks = (ts) => {
|
|
67
|
-
this.tasks.push((cb) => (0, global_acknowledged_time_series_1.GlobalAcknowledgedTimeSeries)(this.redisClient).getRangeFrom(ts, (err, reply) => {
|
|
68
|
-
if (err)
|
|
69
|
-
cb(err);
|
|
70
|
-
else {
|
|
71
|
-
this.redisClient.publish('streamGlobalAcknowledged', JSON.stringify(reply), () => cb());
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
this.tasks.push((cb) => (0, global_dead_lettered_time_series_1.GlobalDeadLetteredTimeSeries)(this.redisClient).getRangeFrom(ts, (err, reply) => {
|
|
75
|
-
if (err)
|
|
76
|
-
cb(err);
|
|
77
|
-
else {
|
|
78
|
-
this.redisClient.publish('streamGlobalDeadLettered', JSON.stringify(reply), () => cb());
|
|
79
|
-
}
|
|
80
|
-
}));
|
|
81
|
-
this.tasks.push((cb) => (0, global_published_time_series_1.GlobalPublishedTimeSeries)(this.redisClient).getRangeFrom(ts, (err, reply) => {
|
|
82
|
-
if (err)
|
|
83
|
-
cb(err);
|
|
84
|
-
else {
|
|
85
|
-
this.redisClient.publish('streamGlobalPublished', JSON.stringify(reply), () => cb());
|
|
86
|
-
}
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
89
|
-
this.addQueue = (queue) => {
|
|
90
|
-
const { ns, name } = queue;
|
|
91
|
-
if (!this.queueData[ns]) {
|
|
92
|
-
this.queueData[ns] = {};
|
|
93
|
-
}
|
|
94
|
-
if (!this.queueData[ns][name]) {
|
|
95
|
-
this.queueData[ns][name] = {
|
|
96
|
-
consumers: [],
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return this.queueData[ns][name];
|
|
100
|
-
};
|
|
101
|
-
this.handleQueueConsumers = (ts, queue, consumers, cb) => {
|
|
102
|
-
(0, async_1.each)(consumers, (consumerId, _, done) => {
|
|
103
|
-
this.addConsumerTasks(ts, queue, consumerId);
|
|
104
|
-
done();
|
|
105
|
-
}, cb);
|
|
106
|
-
};
|
|
107
|
-
this.handleQueue = (ts, queue, queueProperties, cb) => {
|
|
108
|
-
const { consumers } = queueProperties;
|
|
109
|
-
this.addQueueTasks(ts, queue);
|
|
110
|
-
this.handleQueueConsumers(ts, queue, consumers, cb);
|
|
111
|
-
};
|
|
112
|
-
this.prepare = (cb) => {
|
|
113
|
-
const ts = time_series_1.TimeSeries.getCurrentTimestamp();
|
|
114
|
-
this.addGlobalTasks(ts);
|
|
115
|
-
(0, async_1.each)(this.queueData, (queues, ns, done) => {
|
|
116
|
-
(0, async_1.each)(queues, (queue, queueName, done) => {
|
|
117
|
-
this.handleQueue(ts, { ns: String(ns), name: String(queueName) }, queue, done);
|
|
118
|
-
}, done);
|
|
119
|
-
}, cb);
|
|
39
|
+
this.publishQueueTimeSeries = (queue, cb) => {
|
|
40
|
+
(0, async_1.waterfall)([
|
|
41
|
+
(cb) => (0, queue_acknowledged_time_series_1.QueueAcknowledgedTimeSeries)(this.redisClient, queue).getRangeFrom(this.timestamp, (err, reply) => {
|
|
42
|
+
if (err)
|
|
43
|
+
cb(err);
|
|
44
|
+
else {
|
|
45
|
+
this.redisClient.publish(`streamQueueAcknowledged:${queue.ns}:${queue.name}`, JSON.stringify(reply), () => cb());
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
(cb) => (0, queue_dead_lettered_time_series_1.QueueDeadLetteredTimeSeries)(this.redisClient, queue).getRangeFrom(this.timestamp, (err, reply) => {
|
|
49
|
+
if (err)
|
|
50
|
+
cb(err);
|
|
51
|
+
else {
|
|
52
|
+
this.redisClient.publish(`streamQueueDeadLettered:${queue.ns}:${queue.name}`, JSON.stringify(reply), () => cb());
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
(cb) => (0, queue_published_time_series_1.QueuePublishedTimeSeries)(this.redisClient, queue).getRangeFrom(this.timestamp, (err, reply) => {
|
|
56
|
+
if (err)
|
|
57
|
+
cb(err);
|
|
58
|
+
else {
|
|
59
|
+
this.redisClient.publish(`streamQueuePublished:${queue.ns}:${queue.name}`, JSON.stringify(reply), () => cb());
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
], cb);
|
|
120
63
|
};
|
|
121
|
-
this.
|
|
122
|
-
(0, async_1.waterfall)(
|
|
64
|
+
this.handleGlobalTimeSeries = (cb) => {
|
|
65
|
+
(0, async_1.waterfall)([
|
|
66
|
+
(cb) => (0, global_acknowledged_time_series_1.GlobalAcknowledgedTimeSeries)(this.redisClient).getRangeFrom(this.timestamp, (err, reply) => {
|
|
67
|
+
if (err)
|
|
68
|
+
cb(err);
|
|
69
|
+
else {
|
|
70
|
+
this.redisClient.publish('streamGlobalAcknowledged', JSON.stringify(reply), () => cb());
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
(cb) => (0, global_dead_lettered_time_series_1.GlobalDeadLetteredTimeSeries)(this.redisClient).getRangeFrom(this.timestamp, (err, reply) => {
|
|
74
|
+
if (err)
|
|
75
|
+
cb(err);
|
|
76
|
+
else {
|
|
77
|
+
this.redisClient.publish('streamGlobalDeadLettered', JSON.stringify(reply), () => cb());
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
(cb) => (0, global_published_time_series_1.GlobalPublishedTimeSeries)(this.redisClient).getRangeFrom(this.timestamp, (err, reply) => {
|
|
81
|
+
if (err)
|
|
82
|
+
cb(err);
|
|
83
|
+
else {
|
|
84
|
+
this.redisClient.publish('streamGlobalPublished', JSON.stringify(reply), () => cb());
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
], cb);
|
|
123
88
|
};
|
|
124
|
-
this.
|
|
89
|
+
this.handleConsumersTimeSeries = (cb) => {
|
|
125
90
|
consumer_heartbeat_1.ConsumerHeartbeat.getValidHeartbeatIds(this.redisClient, (err, reply) => {
|
|
126
91
|
if (err)
|
|
127
92
|
cb(err);
|
|
@@ -132,9 +97,7 @@ class WebsocketRateStreamWorker extends worker_1.Worker {
|
|
|
132
97
|
done(err);
|
|
133
98
|
else {
|
|
134
99
|
(0, async_1.each)(queues !== null && queues !== void 0 ? queues : [], (queueParams, _, done) => {
|
|
135
|
-
|
|
136
|
-
queue.consumers.push(consumerId);
|
|
137
|
-
done();
|
|
100
|
+
this.publishConsumerTimeSeries(queueParams, consumerId, done);
|
|
138
101
|
}, done);
|
|
139
102
|
}
|
|
140
103
|
});
|
|
@@ -142,7 +105,7 @@ class WebsocketRateStreamWorker extends worker_1.Worker {
|
|
|
142
105
|
}
|
|
143
106
|
});
|
|
144
107
|
};
|
|
145
|
-
this.
|
|
108
|
+
this.handleQueuesTimeSeries = (cb) => {
|
|
146
109
|
const { keyQueues } = redis_keys_1.redisKeys.getMainKeys();
|
|
147
110
|
this.redisClient.smembers(keyQueues, (err, reply) => {
|
|
148
111
|
if (err)
|
|
@@ -150,15 +113,21 @@ class WebsocketRateStreamWorker extends worker_1.Worker {
|
|
|
150
113
|
else {
|
|
151
114
|
(0, async_1.each)(reply !== null && reply !== void 0 ? reply : [], (queueStr, index, done) => {
|
|
152
115
|
const queue = JSON.parse(queueStr);
|
|
153
|
-
this.
|
|
154
|
-
done();
|
|
116
|
+
this.publishQueueTimeSeries(queue, done);
|
|
155
117
|
}, cb);
|
|
156
118
|
}
|
|
157
119
|
});
|
|
158
120
|
};
|
|
159
121
|
this.work = (cb) => {
|
|
160
|
-
this.
|
|
161
|
-
|
|
122
|
+
if (!this.timestamp)
|
|
123
|
+
this.timestamp = Math.ceil(Date.now() / 1000);
|
|
124
|
+
else
|
|
125
|
+
this.timestamp += 1;
|
|
126
|
+
(0, async_1.waterfall)([
|
|
127
|
+
this.handleGlobalTimeSeries,
|
|
128
|
+
this.handleQueuesTimeSeries,
|
|
129
|
+
this.handleConsumersTimeSeries,
|
|
130
|
+
], cb);
|
|
162
131
|
};
|
|
163
132
|
}
|
|
164
133
|
}
|