@hotmeshio/hotmesh 0.0.44 → 0.0.45
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/README.md +1 -1
- package/build/package.json +1 -1
- package/build/services/durable/client.js +7 -8
- package/build/services/quorum/index.js +3 -1
- package/build/services/router/index.js +2 -2
- package/build/services/worker/index.js +1 -0
- package/build/types/quorum.d.ts +1 -0
- package/package.json +1 -1
- package/services/durable/client.ts +7 -8
- package/services/quorum/index.ts +7 -2
- package/services/router/index.ts +3 -2
- package/services/worker/index.ts +2 -1
- package/types/quorum.ts +1 -0
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ HotMesh inverts the relationship to Redis: those functions that once used Redis
|
|
|
19
19
|
|
|
20
20
|
HotMesh creates an *ad hoc*, Redis-backed network of functions and organizes them into a unified service mesh. *Any service with access to Redis can join in the network, bypassing the legacy clutter.*
|
|
21
21
|
|
|
22
|
-
<img src="
|
|
22
|
+
<img src="https://github.com/hotmeshio/sdk-typescript/tree/main/docs/img/hotmesh_emergent_properties.png" alt="HotMesh elevates Redis to a Service Mesh, Message Router, Integration Bus, and Business Process Engine." style="max-width:100%;width:600px;">
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
## Design
|
package/build/package.json
CHANGED
|
@@ -12,11 +12,10 @@ const utils_1 = require("../../modules/utils");
|
|
|
12
12
|
class ClientService {
|
|
13
13
|
constructor(config) {
|
|
14
14
|
this.getHotMeshClient = async (workflowTopic, namespace) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await this.verifyWorkflowActive(hotMeshClient, namespace ?? factory_1.APP_ID);
|
|
15
|
+
const targetNS = namespace ?? factory_1.APP_ID;
|
|
16
|
+
if (ClientService.instances.has(targetNS)) {
|
|
17
|
+
const hotMeshClient = await ClientService.instances.get(targetNS);
|
|
18
|
+
await this.verifyWorkflowActive(hotMeshClient, targetNS);
|
|
20
19
|
if (!ClientService.topics.includes(workflowTopic)) {
|
|
21
20
|
ClientService.topics.push(workflowTopic);
|
|
22
21
|
await this.createStream(hotMeshClient, workflowTopic, namespace);
|
|
@@ -25,7 +24,7 @@ class ClientService {
|
|
|
25
24
|
}
|
|
26
25
|
//create and cache an instance
|
|
27
26
|
const hotMeshClient = hotmesh_1.HotMeshService.init({
|
|
28
|
-
appId:
|
|
27
|
+
appId: targetNS,
|
|
29
28
|
logLevel: enums_1.HMSH_LOGLEVEL,
|
|
30
29
|
engine: {
|
|
31
30
|
redis: {
|
|
@@ -34,9 +33,9 @@ class ClientService {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
|
-
ClientService.instances.set(
|
|
36
|
+
ClientService.instances.set(targetNS, hotMeshClient);
|
|
38
37
|
await this.createStream(await hotMeshClient, workflowTopic, namespace);
|
|
39
|
-
await this.activateWorkflow(await hotMeshClient,
|
|
38
|
+
await this.activateWorkflow(await hotMeshClient, targetNS);
|
|
40
39
|
return hotMeshClient;
|
|
41
40
|
};
|
|
42
41
|
/**
|
|
@@ -99,12 +99,14 @@ class QuorumService {
|
|
|
99
99
|
async sayPong(appId, guid, originator, details = false) {
|
|
100
100
|
let profile;
|
|
101
101
|
if (details) {
|
|
102
|
+
const stream = this.engine.stream.mintKey(hotmesh_1.KeyType.STREAMS, { appId: this.appId });
|
|
102
103
|
profile = {
|
|
103
104
|
engine_id: this.guid,
|
|
104
105
|
namespace: this.namespace,
|
|
105
106
|
app_id: this.appId,
|
|
106
|
-
stream
|
|
107
|
+
stream,
|
|
107
108
|
counts: this.engine.router.counts,
|
|
109
|
+
timestamp: (0, utils_1.formatISODate)(new Date()),
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
this.store.publish(hotmesh_1.KeyType.QUORUM, {
|
|
@@ -31,6 +31,8 @@ class Router {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
async publishMessage(topic, streamData, multi) {
|
|
34
|
+
const code = streamData?.code || '200';
|
|
35
|
+
this.counts[code] = (this.counts[code] || 0) + 1;
|
|
34
36
|
const stream = this.store.mintKey(key_1.KeyType.STREAMS, { appId: this.store.appId, topic });
|
|
35
37
|
return await this.store.xadd(stream, '*', 'message', JSON.stringify(streamData), multi);
|
|
36
38
|
}
|
|
@@ -147,8 +149,6 @@ class Router {
|
|
|
147
149
|
else {
|
|
148
150
|
output.metadata.guid = (0, utils_1.guid)();
|
|
149
151
|
}
|
|
150
|
-
const code = output.code || 200;
|
|
151
|
-
this.counts[code] = (this.counts[code] || 0) + 1;
|
|
152
152
|
output.type = stream_1.StreamDataType.RESPONSE;
|
|
153
153
|
return await this.publishMessage(null, output);
|
|
154
154
|
}
|
|
@@ -115,6 +115,7 @@ class WorkerService {
|
|
|
115
115
|
worker_topic: this.topic,
|
|
116
116
|
stream: this.stream.mintKey(key_1.KeyType.STREAMS, params),
|
|
117
117
|
counts: this.router.counts,
|
|
118
|
+
timestamp: (0, utils_1.formatISODate)(new Date()),
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
this.store.publish(key_1.KeyType.QUORUM, {
|
package/build/types/quorum.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -26,11 +26,10 @@ export class ClientService {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
getHotMeshClient = async (workflowTopic: string, namespace?: string) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await this.verifyWorkflowActive(hotMeshClient, namespace ?? APP_ID);
|
|
29
|
+
const targetNS = namespace ?? APP_ID;
|
|
30
|
+
if (ClientService.instances.has(targetNS)) {
|
|
31
|
+
const hotMeshClient = await ClientService.instances.get(targetNS);
|
|
32
|
+
await this.verifyWorkflowActive(hotMeshClient, targetNS);
|
|
34
33
|
if (!ClientService.topics.includes(workflowTopic)) {
|
|
35
34
|
ClientService.topics.push(workflowTopic);
|
|
36
35
|
await this.createStream(hotMeshClient, workflowTopic, namespace);
|
|
@@ -40,7 +39,7 @@ export class ClientService {
|
|
|
40
39
|
|
|
41
40
|
//create and cache an instance
|
|
42
41
|
const hotMeshClient = HotMesh.init({
|
|
43
|
-
appId:
|
|
42
|
+
appId: targetNS,
|
|
44
43
|
logLevel: HMSH_LOGLEVEL,
|
|
45
44
|
engine: {
|
|
46
45
|
redis: {
|
|
@@ -49,9 +48,9 @@ export class ClientService {
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
|
-
ClientService.instances.set(
|
|
51
|
+
ClientService.instances.set(targetNS, hotMeshClient);
|
|
53
52
|
await this.createStream(await hotMeshClient, workflowTopic, namespace);
|
|
54
|
-
await this.activateWorkflow(await hotMeshClient,
|
|
53
|
+
await this.activateWorkflow(await hotMeshClient, targetNS);
|
|
55
54
|
return hotMeshClient;
|
|
56
55
|
}
|
|
57
56
|
|
package/services/quorum/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HMSH_ACTIVATION_MAX_RETRY, HMSH_QUORUM_DELAY_MS } from '../../modules/enums';
|
|
2
|
-
import { identifyRedisType, sleepFor } from '../../modules/utils';
|
|
2
|
+
import { formatISODate, identifyRedisType, sleepFor } from '../../modules/utils';
|
|
3
3
|
import { CompilerService } from '../compiler';
|
|
4
4
|
import { EngineService } from '../engine';
|
|
5
5
|
import { ILogger } from '../logger';
|
|
@@ -141,12 +141,17 @@ class QuorumService {
|
|
|
141
141
|
async sayPong(appId: string, guid: string, originator: string, details = false) {
|
|
142
142
|
let profile: QuorumProfile;
|
|
143
143
|
if (details) {
|
|
144
|
+
const stream = this.engine.stream.mintKey(
|
|
145
|
+
KeyType.STREAMS,
|
|
146
|
+
{ appId: this.appId }
|
|
147
|
+
);
|
|
144
148
|
profile = {
|
|
145
149
|
engine_id: this.guid,
|
|
146
150
|
namespace: this.namespace,
|
|
147
151
|
app_id: this.appId,
|
|
148
|
-
stream
|
|
152
|
+
stream,
|
|
149
153
|
counts: this.engine.router.counts,
|
|
154
|
+
timestamp: formatISODate(new Date()),
|
|
150
155
|
};
|
|
151
156
|
}
|
|
152
157
|
this.store.publish(
|
package/services/router/index.ts
CHANGED
|
@@ -65,6 +65,9 @@ class Router {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
async publishMessage(topic: string, streamData: StreamData|StreamDataResponse, multi?: RedisMulti): Promise<string | RedisMulti> {
|
|
68
|
+
const code = streamData?.code || '200';
|
|
69
|
+
this.counts[code] = (this.counts[code] || 0) + 1;
|
|
70
|
+
|
|
68
71
|
const stream = this.store.mintKey(KeyType.STREAMS, { appId: this.store.appId, topic });
|
|
69
72
|
return await this.store.xadd(stream, '*', 'message', JSON.stringify(streamData), multi);
|
|
70
73
|
}
|
|
@@ -184,8 +187,6 @@ class Router {
|
|
|
184
187
|
} else {
|
|
185
188
|
output.metadata.guid = guid();
|
|
186
189
|
}
|
|
187
|
-
const code = output.code || 200;
|
|
188
|
-
this.counts[code] = (this.counts[code] || 0) + 1;
|
|
189
190
|
output.type = StreamDataType.RESPONSE;
|
|
190
191
|
return await this.publishMessage(null, output as StreamDataResponse) as string;
|
|
191
192
|
}
|
package/services/worker/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyType } from "../../modules/key";
|
|
2
|
-
import { identifyRedisType } from "../../modules/utils";
|
|
2
|
+
import { formatISODate, identifyRedisType } from "../../modules/utils";
|
|
3
3
|
import { ConnectorService } from "../connector";
|
|
4
4
|
import { ILogger } from "../logger";
|
|
5
5
|
import { Router } from "../router";
|
|
@@ -175,6 +175,7 @@ class WorkerService {
|
|
|
175
175
|
worker_topic: this.topic,
|
|
176
176
|
stream: this.stream.mintKey(KeyType.STREAMS, params),
|
|
177
177
|
counts: this.router.counts,
|
|
178
|
+
timestamp: formatISODate(new Date()),
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
this.store.publish(
|