@nsshunt/stsappframework 3.0.187 → 3.1.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/build.sh +0 -1
- package/dist/authutilsnode.js +3 -9
- package/dist/authutilsnode.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/influxdb/influxDBManager.js +15 -18
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +1 -4
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +2 -4
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +5 -8
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/masterprocessbase.js +7 -0
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/middleware/serverNetworkMiddleware.js +1 -56
- package/dist/middleware/serverNetworkMiddleware.js.map +1 -1
- package/dist/publishertransports/publishTransportDirect.js.map +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/singleprocessbase.js +7 -1
- package/dist/singleprocessbase.js.map +1 -1
- package/dist/socketIoServerHelper.js +15 -12
- package/dist/socketIoServerHelper.js.map +1 -1
- package/dist/stsAppFrameworkTransportWinston.js +24 -0
- package/dist/stsAppFrameworkTransportWinston.js.map +1 -0
- package/dist/stsTransportLoggerWinston.js.map +1 -1
- package/dist/{stsTransportDebuggerWinston.js → stsTransportWinston.js} +5 -5
- package/dist/stsTransportWinston.js.map +1 -0
- package/dist/testing/appConfig.js +1 -1
- package/dist/testing/appConfig.js.map +1 -1
- package/dist/vitesttesting/appConfig.js +94 -0
- package/dist/vitesttesting/appConfig.js.map +1 -0
- package/dist/vitesttesting/appSingleWSS.js +73 -0
- package/dist/vitesttesting/appSingleWSS.js.map +1 -0
- package/dist/vitesttesting/server.js +16 -0
- package/dist/vitesttesting/server.js.map +1 -0
- package/dist/{testing → vitesttesting}/singleservertest.test.js +5 -111
- package/dist/vitesttesting/singleservertest.test.js.map +1 -0
- package/dist/vitesttesting/wsevents.js +3 -0
- package/dist/vitesttesting/wsevents.js.map +1 -0
- package/dist/workerprocessbase.js +7 -1
- package/dist/workerprocessbase.js.map +1 -1
- package/package.json +1 -1
- package/src/authutilsnode.ts +10 -20
- package/src/commonTypes.ts +2 -2
- package/src/index.ts +2 -2
- package/src/influxdb/influxDBManager.ts +15 -19
- package/src/influxdb/influxDBManagerAgent.ts +1 -5
- package/src/influxdb/influxDBManagerService.ts +1 -5
- package/src/kafka/IMKafkaManager.ts +5 -9
- package/src/masterprocessbase.ts +7 -1
- package/src/middleware/serverNetworkMiddleware.ts +3 -58
- package/src/publishertransports/publishTransportDirect.ts +1 -0
- package/src/server.ts +2 -1
- package/src/singleprocessbase.ts +8 -1
- package/src/socketIoServerHelper.ts +12 -13
- package/src/stsAppFrameworkTransportWinston.ts +28 -0
- package/src/stsTransportLoggerWinston.ts +4 -3
- package/src/{stsTransportDebuggerWinston.ts → stsTransportWinston.ts} +6 -6
- package/src/testing/appConfig.ts +1 -1
- package/src/vitesttesting/appConfig.ts +110 -0
- package/src/vitesttesting/appSingleWSS.ts +82 -0
- package/src/vitesttesting/server.ts +18 -0
- package/src/{testing → vitesttesting}/singleservertest.test.ts +7 -128
- package/src/vitesttesting/wsevents.ts +33 -0
- package/src/workerprocessbase.ts +8 -1
- package/types/authutilsnode.d.ts +1 -5
- package/types/authutilsnode.d.ts.map +1 -1
- package/types/commonTypes.d.ts +2 -2
- package/types/commonTypes.d.ts.map +1 -1
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +1 -1
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/middleware/serverNetworkMiddleware.d.ts +2 -1
- package/types/middleware/serverNetworkMiddleware.d.ts.map +1 -1
- package/types/publishertransports/publishTransportDirect.d.ts.map +1 -1
- package/types/server.d.ts.map +1 -1
- package/types/singleprocessbase.d.ts +1 -1
- package/types/singleprocessbase.d.ts.map +1 -1
- package/types/socketIoServerHelper.d.ts.map +1 -1
- package/types/stsAppFrameworkTransportWinston.d.ts +12 -0
- package/types/stsAppFrameworkTransportWinston.d.ts.map +1 -0
- package/types/stsTransportLoggerWinston.d.ts +1 -2
- package/types/stsTransportLoggerWinston.d.ts.map +1 -1
- package/types/{stsTransportDebuggerWinston.d.ts → stsTransportWinston.d.ts} +4 -4
- package/types/stsTransportWinston.d.ts.map +1 -0
- package/types/vitesttesting/appConfig.d.ts +3 -0
- package/types/vitesttesting/appConfig.d.ts.map +1 -0
- package/types/vitesttesting/appSingleWSS.d.ts +8 -0
- package/types/vitesttesting/appSingleWSS.d.ts.map +1 -0
- package/types/vitesttesting/server.d.ts +6 -0
- package/types/vitesttesting/server.d.ts.map +1 -0
- package/types/vitesttesting/singleservertest.test.d.ts.map +1 -0
- package/types/vitesttesting/wsevents.d.ts +18 -0
- package/types/vitesttesting/wsevents.d.ts.map +1 -0
- package/types/workerprocessbase.d.ts +1 -1
- package/types/workerprocessbase.d.ts.map +1 -1
- package/dist/stsTransportDebuggerWinston.js.map +0 -1
- package/dist/testing/singleservertest.test.js.map +0 -1
- package/dist/workerprocessbase.test.js +0 -42
- package/dist/workerprocessbase.test.js.map +0 -1
- package/src/workerprocessbase.test.ts +0 -47
- package/types/stsTransportDebuggerWinston.d.ts.map +0 -1
- package/types/testing/singleservertest.test.d.ts.map +0 -1
- package/types/workerprocessbase.test.d.ts +0 -2
- package/types/workerprocessbase.test.d.ts.map +0 -1
- /package/types/{testing → vitesttesting}/singleservertest.test.d.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
2
|
|
|
3
3
|
//import Debug from "debug";
|
|
4
|
+
//const debug = Debug(`proc:${process.pid}:PublishRESTServer`);
|
|
4
5
|
|
|
5
6
|
import { IPublisherTransport, IInstrumentPayload } from '@nsshunt/stspublisherserver'
|
|
6
7
|
import { IMKafkaManager } from './../kafka/IMKafkaManager'
|
package/src/server.ts
CHANGED
|
@@ -29,7 +29,8 @@ export class STSExpressServer
|
|
|
29
29
|
|
|
30
30
|
const serverNetworkMiddleware = new ServerNetworkMiddleware({
|
|
31
31
|
name: (stsApp.options as ProcessOptions).serviceName,
|
|
32
|
-
outputDebug: false
|
|
32
|
+
outputDebug: false,
|
|
33
|
+
logger: stsApp.options?.logger
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
serverNetworkMiddleware.on(ServerNetworkMiddlewareEventName.UpdateInstrument_SERVER_NET_VAL, (data: ISocketRecord) => {
|
package/src/singleprocessbase.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { ServerProcessBase } from './serverprocessbase'
|
|
|
14
14
|
|
|
15
15
|
import si from 'systeminformation' // https://systeminformation.io/
|
|
16
16
|
|
|
17
|
+
import { STSTransportLoggerWinston } from './stsTransportLoggerWinston'
|
|
18
|
+
|
|
17
19
|
export type EventCb = (socket: any, data: any) => void
|
|
18
20
|
|
|
19
21
|
export class SingleProcessBase extends ServerProcessBase implements ISingleProcessBase
|
|
@@ -55,7 +57,12 @@ export class SingleProcessBase extends ServerProcessBase implements ISingleProce
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
ProcessStarted() {
|
|
58
|
-
|
|
60
|
+
const transport = new STSTransportLoggerWinston({
|
|
61
|
+
stsApp: this
|
|
62
|
+
});
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
(this.options.logger as any).add(transport);
|
|
65
|
+
}, 0);
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
SetupServer(): Promise<boolean>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
+
import Debug from "debug";
|
|
3
|
+
const debug = Debug(`proc:${process.pid}:socketiohelper`);
|
|
4
|
+
|
|
2
5
|
import { JSONObject, ISTSLogger } from '@nsshunt/stsutils'
|
|
3
6
|
|
|
4
7
|
import { Server, Namespace, Socket } from "socket.io";
|
|
@@ -23,10 +26,6 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
23
26
|
|
|
24
27
|
#namespace: Record<string, STSSocketIONamespace> = { };
|
|
25
28
|
|
|
26
|
-
#LogDebugMessage(message: any) {
|
|
27
|
-
this.#socketIoServerHelperOptions.logger.debug(message);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
29
|
LogMessage = (namespace: STSSocketIONamespace, message: string): void => {
|
|
31
30
|
|
|
32
31
|
this.#socketIoServerHelperOptions.logger.info(`${namespace.namespace}: ${message}`);
|
|
@@ -39,32 +38,32 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
39
38
|
|
|
40
39
|
LeaveRoom = (namespace: STSSocketIONamespace, socket: Socket<ClientToServerEvents, ServerToClientEvents>, room: string): void => {
|
|
41
40
|
const logMessage = `${namespace.socketionamespace.name}: Leaving room [${room}]`;
|
|
42
|
-
|
|
41
|
+
debug(logMessage);
|
|
43
42
|
this.LogMessage(namespace, logMessage);
|
|
44
43
|
socket.leave(room);
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
JoinRoom = (namespace: STSSocketIONamespace, socket: Socket<ClientToServerEvents, ServerToClientEvents>, room: string): void => {
|
|
48
47
|
const logMessage = `${namespace.socketionamespace.name}: Socket joining room [${room}], ID: [${socket.id}]`;
|
|
49
|
-
|
|
48
|
+
debug(logMessage);
|
|
50
49
|
this.LogMessage(namespace, logMessage);
|
|
51
50
|
socket.join(room);
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
#SetupStandardEvents = (namespace: STSSocketIONamespace, socket: Socket<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents>): void => {
|
|
55
54
|
socket.on("__STSdisconnect", (reason) => {
|
|
56
|
-
|
|
55
|
+
debug(`${namespace.socketionamespace.name}: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
socket.on("__STSdisconnecting", (reason, callBackResult) => {
|
|
60
|
-
|
|
59
|
+
debug(`${namespace.socketionamespace.name}: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
61
60
|
callBackResult("__STSdisconnecting accepted by server.");
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
socket.on('__STSjoinRoom', (rooms: string[]): void => { //@@ names
|
|
65
64
|
rooms.forEach((room) => {
|
|
66
65
|
const logMessage = `${namespace.socketionamespace.name}:socket.on:joinRoom: Socket joining room [${room}], ID: [${socket.id}]`;
|
|
67
|
-
|
|
66
|
+
debug(logMessage);
|
|
68
67
|
this.JoinRoom(namespace, socket, room)
|
|
69
68
|
});
|
|
70
69
|
});
|
|
@@ -72,7 +71,7 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
72
71
|
socket.on('__STSleaveRoom', (rooms: string[]): void => { //@@ names
|
|
73
72
|
rooms.forEach((room) => {
|
|
74
73
|
const logMessage = `${namespace.socketionamespace.name}:socket.on:joinRoom: Socket leaving room [${room}], ID: [${socket.id}]`;
|
|
75
|
-
|
|
74
|
+
debug(logMessage);
|
|
76
75
|
this.LeaveRoom(namespace, socket, room);
|
|
77
76
|
});
|
|
78
77
|
});
|
|
@@ -80,7 +79,7 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
80
79
|
socket.on('__STSsendToRoom', (rooms: string[], payload: { command: string, payload: JSONObject }): void => {
|
|
81
80
|
rooms.forEach((room) => {
|
|
82
81
|
const logMessage = `${namespace.socketionamespace.name}:socket.on:sendToRoom: Sending to room [${room}], ID: [${socket.id}]`;
|
|
83
|
-
|
|
82
|
+
debug(logMessage);
|
|
84
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
84
|
namespace.socketionamespace.to(room).emit(payload.command as any, payload);
|
|
86
85
|
});
|
|
@@ -132,9 +131,9 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
132
131
|
|
|
133
132
|
this.#namespace[namespace].socketionamespace.on("connection", socket => {
|
|
134
133
|
const logMessage = `${namespace}: Socket connected, ID: [${socket.id}]`;
|
|
135
|
-
|
|
134
|
+
debug(logMessage);
|
|
136
135
|
this.LogMessage(this.#namespace[namespace], logMessage);
|
|
137
|
-
|
|
136
|
+
debug(`${namespace}: Authentication Handshake: [${JSON.stringify(socket.handshake.auth)}]`);
|
|
138
137
|
|
|
139
138
|
this.#SetupMessageMiddleware(socket);
|
|
140
139
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import Transport, { TransportStreamOptions } from 'winston-transport'
|
|
3
|
+
|
|
4
|
+
import { IProcessBase } from './commonTypes'
|
|
5
|
+
|
|
6
|
+
export interface ISTSAppFrameworkTransportWinstonOptions extends TransportStreamOptions {
|
|
7
|
+
stsContext: string
|
|
8
|
+
app: IProcessBase
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class STSAppFrameworkTransportWinston extends Transport {
|
|
12
|
+
|
|
13
|
+
#options: ISTSAppFrameworkTransportWinstonOptions;
|
|
14
|
+
|
|
15
|
+
constructor(opts: ISTSAppFrameworkTransportWinstonOptions) {
|
|
16
|
+
super(opts);
|
|
17
|
+
this.#options = opts;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
log(info: any, callback: any) {
|
|
21
|
+
//setImmediate(() => {
|
|
22
|
+
this.#options.app.LogEx(info.message);
|
|
23
|
+
|
|
24
|
+
this.emit('logged', info);
|
|
25
|
+
callback();
|
|
26
|
+
//});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
2
|
import Transport, { TransportStreamOptions } from 'winston-transport'
|
|
3
|
+
|
|
3
4
|
import { IProcessBase } from './commonTypes'
|
|
4
5
|
|
|
5
|
-
interface ISTSTransportLoggerWinstonOptions extends TransportStreamOptions {
|
|
6
|
-
//stsContext: string
|
|
6
|
+
export interface ISTSTransportLoggerWinstonOptions extends TransportStreamOptions {
|
|
7
7
|
stsApp: IProcessBase
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class STSTransportLoggerWinston extends Transport {
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
#options: ISTSTransportLoggerWinstonOptions;
|
|
12
13
|
|
|
13
14
|
constructor(opts: ISTSTransportLoggerWinstonOptions) {
|
|
14
15
|
super(opts);
|
|
@@ -3,25 +3,25 @@ import Transport, { TransportStreamOptions } from 'winston-transport'
|
|
|
3
3
|
|
|
4
4
|
import debugModule from 'debug'
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface ISTSTransportWinstonOptions extends TransportStreamOptions {
|
|
7
7
|
stsContext: string
|
|
8
8
|
debugger?: debugModule.Debugger
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function UpdateSTSTransportWithDebugger(logger: any, newDebugger: any): void {
|
|
12
12
|
const stsTransport: Transport | undefined = logger.transports.find((transport: any) => {
|
|
13
|
-
return transport instanceof
|
|
13
|
+
return transport instanceof STSTransportWinston
|
|
14
14
|
});
|
|
15
15
|
if (stsTransport) {
|
|
16
|
-
(stsTransport as
|
|
16
|
+
(stsTransport as STSTransportWinston).debugger = newDebugger
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export class
|
|
20
|
+
export class STSTransportWinston extends Transport {
|
|
21
21
|
|
|
22
|
-
#options:
|
|
22
|
+
#options: ISTSTransportWinstonOptions;
|
|
23
23
|
|
|
24
|
-
constructor(opts:
|
|
24
|
+
constructor(opts: ISTSTransportWinstonOptions) {
|
|
25
25
|
super(opts);
|
|
26
26
|
this.#options = opts;
|
|
27
27
|
}
|
package/src/testing/appConfig.ts
CHANGED
|
@@ -85,7 +85,7 @@ export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): P
|
|
|
85
85
|
instrumentationTimeWindow: goptions.instrumentationTimeWindow,
|
|
86
86
|
|
|
87
87
|
useRedisAdaptor: false,
|
|
88
|
-
workerExec: './dist/testing/app.js',
|
|
88
|
+
//workerExec: './dist/testing/app.js',
|
|
89
89
|
|
|
90
90
|
logger: logger,
|
|
91
91
|
publisherLogger: publisherLogger
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
|
|
4
|
+
import { $Options } from '@nsshunt/stsconfig'
|
|
5
|
+
const goptions = $Options()
|
|
6
|
+
|
|
7
|
+
import { ProcessOptions, IProcessBase, STSServerType } from './..'
|
|
8
|
+
|
|
9
|
+
import { STSExpressRouteFactory } from './server'
|
|
10
|
+
|
|
11
|
+
import winston from 'winston'
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
// nid: `${goptions.rest01servicename} @ ${goptions.rest01serviceversion} | ${this.options.globalServiceData.serviceInstanceId} @ ${os.hostname()} ^ ${process.pid} @ ${(cluster.isMaster ? process.pid : process.ppid)}`,
|
|
15
|
+
// <serviceId> <serviceInstanceId> <serviceInstanceProcessId>
|
|
16
|
+
// <serviceName> <serviceVersion> <sid> <hostName> <pid> <ppid>
|
|
17
|
+
// << ............... Static Nid ............... >> << ............... Dynamic Nid ............... >>
|
|
18
|
+
// Note: The final nid will NOT contain the NID_SEPERATOR character. This will be replaced with the SEPERATOR character.
|
|
19
|
+
const Context = (isMaster, serviceInstanceId) => {
|
|
20
|
+
return {
|
|
21
|
+
nid: `\
|
|
22
|
+
${goptions.rest01servicename}${ModelDelimeter.COMPONENT_SEPERATOR}${goptions.rest01serviceversion}\
|
|
23
|
+
${ModelDelimeter.SEPERATOR}\
|
|
24
|
+
${serviceInstanceId}${ModelDelimeter.COMPONENT_SEPERATOR}${os.hostname()}\
|
|
25
|
+
${ModelDelimeter.NID_SEPERATOR}\
|
|
26
|
+
${process.pid}${ModelDelimeter.COMPONENT_SEPERATOR}${(isMaster ? process.pid : process.ppid)}`
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): ProcessOptions {
|
|
32
|
+
winston.format.combine(
|
|
33
|
+
winston.format.colorize(),
|
|
34
|
+
winston.format.simple()
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const logger = winston.createLogger({
|
|
38
|
+
level: 'silly',
|
|
39
|
+
format: winston.format.combine(
|
|
40
|
+
winston.format.colorize(),
|
|
41
|
+
winston.format.simple()
|
|
42
|
+
),
|
|
43
|
+
transports: [
|
|
44
|
+
new winston.transports.Console()
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const publisherLogger = winston.createLogger({
|
|
49
|
+
level: 'info',
|
|
50
|
+
format: winston.format.combine(
|
|
51
|
+
winston.format.colorize(),
|
|
52
|
+
winston.format.simple()
|
|
53
|
+
),
|
|
54
|
+
transports: [
|
|
55
|
+
new winston.transports.Console()
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (isMaster === true) {
|
|
60
|
+
const serviceInstanceId = uuidv4();
|
|
61
|
+
const data: ProcessOptions = {
|
|
62
|
+
serverType: STSServerType.EXPRESS_TLS,
|
|
63
|
+
clusterMode: clusterMode,
|
|
64
|
+
wssServer: true,
|
|
65
|
+
useLatency: true,
|
|
66
|
+
httpsServerKeyPath: goptions.httpsserverkeypath,
|
|
67
|
+
httpsServerCertificatePath: goptions.httpsservercertpath,
|
|
68
|
+
processExitOnTerminate: true,
|
|
69
|
+
serviceInstanceId: serviceInstanceId,
|
|
70
|
+
useDatabase: false,
|
|
71
|
+
|
|
72
|
+
isMaster: isMaster,
|
|
73
|
+
endpoint: goptions.rest01endpoint,
|
|
74
|
+
apiRoot: goptions.rest01apiroot,
|
|
75
|
+
listenPort: goptions.rest01hostport,
|
|
76
|
+
port: goptions.rest01port,
|
|
77
|
+
prometheusSupport: goptions.rest01prometheussupport,
|
|
78
|
+
prometheusClusterPort: goptions.rest01prometheusclusterport,
|
|
79
|
+
serviceName: goptions.rest01servicename,
|
|
80
|
+
serviceVersion: goptions.rest01serviceversion,
|
|
81
|
+
consoleLogging: true,
|
|
82
|
+
instrumentLogging: true,
|
|
83
|
+
|
|
84
|
+
instrumentationObservationInterval: goptions.instrumentationObservationInterval,
|
|
85
|
+
instrumentationTimeWindow: goptions.instrumentationTimeWindow,
|
|
86
|
+
|
|
87
|
+
useRedisAdaptor: false,
|
|
88
|
+
//workerExec: './dist/testing/app.js',
|
|
89
|
+
|
|
90
|
+
logger: logger,
|
|
91
|
+
publisherLogger: publisherLogger
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!clusterMode) {
|
|
95
|
+
data.expressServerRouteFactory = (app: express.Express, stsApp: IProcessBase) => {
|
|
96
|
+
return new STSExpressRouteFactory(app, stsApp);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return data;
|
|
101
|
+
} else {
|
|
102
|
+
const data: ProcessOptions = JSON.parse(process.env['STS_GSD_SII'] as string) as ProcessOptions;
|
|
103
|
+
data.expressServerRouteFactory = (app: express.Express, stsApp: IProcessBase) => {
|
|
104
|
+
return new STSExpressRouteFactory(app, stsApp);
|
|
105
|
+
}
|
|
106
|
+
data.logger = logger;
|
|
107
|
+
data.publisherLogger = publisherLogger;
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
import { SingleProcessBase, STSNamespace, STSRoom, SocketIoServerHelper, STSSocketIONamespace, ProcessOptions } from './../index'
|
|
5
|
+
|
|
6
|
+
import { Socket } from "socket.io";
|
|
7
|
+
|
|
8
|
+
import { InterServerEvents } from './../commonTypes'
|
|
9
|
+
|
|
10
|
+
import { ClientToServerEvents, ServerToClientEvents } from './wsevents'
|
|
11
|
+
|
|
12
|
+
export class AppSingleWSS extends SingleProcessBase
|
|
13
|
+
{
|
|
14
|
+
constructor(options: ProcessOptions)
|
|
15
|
+
{
|
|
16
|
+
super(options);
|
|
17
|
+
this.socketIoServerHelper = new SocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>({
|
|
18
|
+
logger: this.options.logger
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#LogErrorMessage(message: any) {
|
|
23
|
+
this.options.logger.error(message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#LogInfoMessage(message: any) {
|
|
27
|
+
this.options.logger.info(message);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override ProcessStarted() {
|
|
31
|
+
super.ProcessStarted();
|
|
32
|
+
|
|
33
|
+
if (this.socketIoServerHelper) {
|
|
34
|
+
this.socketIoServerHelper.SetupNamespace(this.io as any, STSNamespace.STSMonitor,
|
|
35
|
+
// Auto joinn room list
|
|
36
|
+
[
|
|
37
|
+
STSRoom.STSInstrumentDataRoom,
|
|
38
|
+
STSRoom.STSRunnerRoom,
|
|
39
|
+
'room3'
|
|
40
|
+
],
|
|
41
|
+
true, // Make any connecting client automatically join the room list above
|
|
42
|
+
|
|
43
|
+
// Connect call back when a client connects
|
|
44
|
+
(socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => {
|
|
45
|
+
this.#LogInfoMessage(chalk.gray(`WorkerProcess.#SendIPCMessageToMaster: Id: [${socket.id}] eventName: [connect]`));
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Custom client to server events
|
|
49
|
+
(socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => {
|
|
50
|
+
socket.on('subscribe', (data: any) => {
|
|
51
|
+
socket.emit('subscribeAck', data);
|
|
52
|
+
});
|
|
53
|
+
socket.on('unsubscribe', (data: any) => {
|
|
54
|
+
socket.emit('unsubscribeAck', data);
|
|
55
|
+
});
|
|
56
|
+
socket.on('subscribeKeepAlive', (data: any) => {
|
|
57
|
+
socket.emit('subscribeKeepAliveAck', data);
|
|
58
|
+
});
|
|
59
|
+
socket.on('done', () => {
|
|
60
|
+
socket.emit('doneAck');
|
|
61
|
+
});
|
|
62
|
+
socket.on('compute', (arg: number, cb) => {
|
|
63
|
+
const res = arg * 2;
|
|
64
|
+
cb(res.toString());
|
|
65
|
+
});
|
|
66
|
+
socket.on('compute2', (arg, cb) => {
|
|
67
|
+
cb({data: arg*2});
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error('WorkerProcess:WorkerStarted(): this.socketIoHelper is null')
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get stsMonitorNamespace(): STSSocketIONamespace | null {
|
|
77
|
+
if (this.socketIoServerHelper !== null) {
|
|
78
|
+
return this.socketIoServerHelper.GetSTSSocketIONamespace(STSNamespace.STSMonitor);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
|
|
3
|
+
import { STSLatencyRoute, IProcessBase } from './..'
|
|
4
|
+
|
|
5
|
+
import { $Options } from '@nsshunt/stsconfig'
|
|
6
|
+
const goptions = $Options()
|
|
7
|
+
|
|
8
|
+
export class STSExpressRouteFactory
|
|
9
|
+
{
|
|
10
|
+
constructor(app: express.Express, stsApp: IProcessBase)
|
|
11
|
+
{
|
|
12
|
+
const stslatency = new STSLatencyRoute(stsApp);
|
|
13
|
+
|
|
14
|
+
// Note: This MUST come first as the latency end point is on the same path as the reosurce path.
|
|
15
|
+
// If stsresourceRouter came first, it would think that /latency was a resource name.
|
|
16
|
+
app.use(`${goptions.rest01apiroot}`, stslatency.router);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -7,7 +7,9 @@ import chalk from 'chalk';
|
|
|
7
7
|
import axios, { AxiosError, AxiosResponse } from 'axios';
|
|
8
8
|
|
|
9
9
|
import { Sleep } from '@nsshunt/stsutils'
|
|
10
|
-
import { SingleProcessBase, MasterProcessBase } from './..'
|
|
10
|
+
//import { SingleProcessBase, MasterProcessBase } from './..'
|
|
11
|
+
|
|
12
|
+
import { AppSingleWSS } from './appSingleWSS'
|
|
11
13
|
|
|
12
14
|
import { ServiceConfigOptions } from './appConfig'
|
|
13
15
|
|
|
@@ -22,27 +24,12 @@ import { SocketIoClientHelper, ISocketIoClientHelperOptions } from '@nsshunt/sts
|
|
|
22
24
|
|
|
23
25
|
import { STSNamespace } from './../index'
|
|
24
26
|
|
|
25
|
-
//const { Kafka } = require('kafkajs')
|
|
26
|
-
|
|
27
|
-
//import { DockerComposeEnvironment, Wait, AlwaysPullPolicy } from 'testcontainers'
|
|
28
|
-
|
|
29
27
|
import { ServerToClientEvents, ClientToServerEvents } from './wsevents'
|
|
30
28
|
import { Socket } from 'socket.io-client'
|
|
31
|
-
//import { TimeSeriesBucketTimestamp } from 'redis';
|
|
32
29
|
|
|
33
30
|
describe("Single Server Test", () =>
|
|
34
31
|
{
|
|
35
|
-
|
|
36
|
-
const kafka = new Kafka({
|
|
37
|
-
clientId: 'my-app',
|
|
38
|
-
brokers: ['192.168.14.92:9092']
|
|
39
|
-
//brokers: ['localhost:9092', 'kafka2:9092'],
|
|
40
|
-
})
|
|
41
|
-
let producer: any;
|
|
42
|
-
let environment: any;
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
let app: SingleProcessBase | MasterProcessBase | null = null;
|
|
32
|
+
let app: AppSingleWSS | null = null;
|
|
46
33
|
let httpsAgent: https.Agent | null = null;
|
|
47
34
|
|
|
48
35
|
const endpoint = 'https://localhost'
|
|
@@ -58,8 +45,6 @@ describe("Single Server Test", () =>
|
|
|
58
45
|
}
|
|
59
46
|
}
|
|
60
47
|
|
|
61
|
-
// Use ServerToClientEvents<true> when the client will pass a request to server with a call back expected with a timeout
|
|
62
|
-
//@@const socketUtils = new SocketIoClientHelper<ServerToClientEvents<true>, ClientToServerEvents>(socketUtilsoptions);
|
|
63
48
|
const socketUtils = new SocketIoClientHelper<ServerToClientEvents, ClientToServerEvents>(socketUtilsoptions);
|
|
64
49
|
|
|
65
50
|
const instrumentManagerAddress =
|
|
@@ -122,92 +107,11 @@ describe("Single Server Test", () =>
|
|
|
122
107
|
}
|
|
123
108
|
}
|
|
124
109
|
|
|
125
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
|
|
126
|
-
/*
|
|
127
|
-
const socketDetail: ISocketDetail = socketUtils.SetupClientSideSocket('STSUITerm', instrumentManagerAddress, [
|
|
128
|
-
{
|
|
129
|
-
eventName: 'hello',
|
|
130
|
-
eventCb: (socket: any, data: any): void => {
|
|
131
|
-
debug(`Received: [hello:${data}]`);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
eventName: 'goodbye',
|
|
136
|
-
eventCb: (socket: any, data: any) => {
|
|
137
|
-
debug(`Received: [goodbye:${data}]`);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
eventName: 'registerEcho',
|
|
142
|
-
eventCb: (socket: any, data: any) => {
|
|
143
|
-
debug(`Received: [registerEcho:${JSON.stringify(data)}]`);
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
eventName: STSEvent.connect,
|
|
148
|
-
eventCb: (socket: STSClientSocket, data: any) => {
|
|
149
|
-
socket.emit('joinRoom', STSRoom.STSInstrumentDataRoom);
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
eventName: 'sts_connect_reply',
|
|
154
|
-
eventCb: (socket: STSClientSocket, data: any) => {
|
|
155
|
-
debug(`Received: [sts_connect_reply:${JSON.stringify(data)}]`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
]);
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
110
|
beforeAll(async () =>
|
|
162
111
|
{
|
|
163
|
-
|
|
164
|
-
const composeFilePath = "/home/marcusbettens/projects/stsappframework/src/testing";
|
|
165
|
-
const composeFile = "docker-compose.yml";
|
|
166
|
-
try {
|
|
167
|
-
environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
168
|
-
.withWaitStrategy("kafka", Wait.forLogMessage("[KafkaServer id=1001] started (kafka.server.KafkaServer)"))
|
|
169
|
-
.withPullPolicy(new AlwaysPullPolicy())
|
|
170
|
-
.up()
|
|
171
|
-
} catch (error) {
|
|
172
|
-
this.#LogErrorMessage(error)
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
/*
|
|
179
|
-
producer = kafka.producer()
|
|
180
|
-
await producer.connect()
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
/*
|
|
184
|
-
process.env.AS_ENDPOINT = testHelper.authHost;
|
|
185
|
-
process.env.AS_HOST_PORT = testHelper.authPort;
|
|
186
|
-
process.env.AS_PORT = testHelper.authPort;
|
|
187
|
-
|
|
188
|
-
$ResetOptions();
|
|
189
|
-
//goptions = $Options()
|
|
190
|
-
|
|
191
|
-
//goptions.asendpoint = testHelper.authHost;
|
|
192
|
-
//goptions.asport = testHelper.authPort;
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
const clusterMode = true;
|
|
196
|
-
|
|
197
|
-
if (clusterMode) {
|
|
198
|
-
const appOptions = ServiceConfigOptions(clusterMode, true);
|
|
199
|
-
appOptions.processExitOnTerminate = false;
|
|
200
|
-
app = new MasterProcessBase(appOptions)
|
|
201
|
-
} else {
|
|
202
|
-
const appOptions = ServiceConfigOptions(clusterMode, true);
|
|
203
|
-
appOptions.processExitOnTerminate = false;
|
|
204
|
-
app = new SingleProcessBase(appOptions)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const appOptions = ServiceConfigOptions(true, true);
|
|
112
|
+
const appOptions = ServiceConfigOptions(false, true);
|
|
208
113
|
appOptions.processExitOnTerminate = false;
|
|
209
|
-
|
|
210
|
-
app = new MasterProcessBase(appOptions)
|
|
114
|
+
app = new AppSingleWSS(appOptions)
|
|
211
115
|
await app.SetupServer();
|
|
212
116
|
await Sleep(3000);
|
|
213
117
|
}, 60000);
|
|
@@ -216,23 +120,8 @@ describe("Single Server Test", () =>
|
|
|
216
120
|
{
|
|
217
121
|
await Sleep(500);
|
|
218
122
|
|
|
219
|
-
// Kafka disconnect
|
|
220
|
-
//await producer.disconnect()
|
|
221
|
-
|
|
222
|
-
//@@await environment.down();
|
|
223
|
-
|
|
224
|
-
//await (app as SingleProcessBase).TerminateApplication();
|
|
225
123
|
await Sleep(1000);
|
|
226
124
|
app = null;
|
|
227
|
-
|
|
228
|
-
/*
|
|
229
|
-
|
|
230
|
-
await testHelper.StopAuthService();
|
|
231
|
-
await testHelper.StopDatabase();
|
|
232
|
-
await testHelper.StopNetwork();
|
|
233
|
-
|
|
234
|
-
await Sleep(2000);
|
|
235
|
-
*/
|
|
236
125
|
}, 15000);
|
|
237
126
|
|
|
238
127
|
test('Testing Module', async () =>
|
|
@@ -245,16 +134,6 @@ describe("Single Server Test", () =>
|
|
|
245
134
|
const num = 50;
|
|
246
135
|
expect.assertions(num * 2);
|
|
247
136
|
for (let i=0; i < num; i++) {
|
|
248
|
-
|
|
249
|
-
/*
|
|
250
|
-
const retValKafka = await producer.send({
|
|
251
|
-
topic: 'topic-name2',
|
|
252
|
-
messages: [
|
|
253
|
-
{ key: 'key1', value: `hello world - ${i}` },
|
|
254
|
-
],
|
|
255
|
-
})
|
|
256
|
-
*/
|
|
257
|
-
|
|
258
137
|
const retVal = await getLatency();
|
|
259
138
|
const retValObj = retVal?.data.data;
|
|
260
139
|
expect(retValObj).toMatch('Ping Completed At:');
|
|
@@ -272,6 +151,7 @@ describe("Single Server Test", () =>
|
|
|
272
151
|
// The address defines the namespace to connect to (i.e. io.of('/address'))
|
|
273
152
|
instrumentManagerAddress,
|
|
274
153
|
// Connected call back
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
275
155
|
(socket: Socket<ServerToClientEvents, ClientToServerEvents>) => {
|
|
276
156
|
debug(chalk.green(`connected - 1`));
|
|
277
157
|
expect(1).toEqual(1);
|
|
@@ -330,7 +210,6 @@ describe("Single Server Test", () =>
|
|
|
330
210
|
}
|
|
331
211
|
});
|
|
332
212
|
|
|
333
|
-
|
|
334
213
|
while (!complete) {
|
|
335
214
|
await Sleep(100);
|
|
336
215
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import { STSDefaultServerToClientEvents, STSDefaultClientToServerEvents } from '@nsshunt/stssocketio-client'
|
|
3
|
+
|
|
4
|
+
// Syntax sugar from socket.io
|
|
5
|
+
// https://socket.io/docs/v4/typescript/#emitting-with-a-timeout
|
|
6
|
+
//type WithTimeoutAck<isSender extends boolean, args extends any[]> = isSender extends true ? [Error, ...args] : args;
|
|
7
|
+
|
|
8
|
+
//export interface ServerToClientEvents<isSender extends boolean = false> extends STSServerToClientEvents {
|
|
9
|
+
export interface ServerToClientEvents extends STSDefaultServerToClientEvents {
|
|
10
|
+
/*
|
|
11
|
+
noArg: () => void;
|
|
12
|
+
basicEmit: (a: number, b: string, c: Buffer) => void;
|
|
13
|
+
withAck: (d: string, callback: (e: number) => void) => void;
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
subscribeAck: (data: any) => void;
|
|
17
|
+
unsubscribeAck: (data: any) => void;
|
|
18
|
+
subscribeKeepAliveAck: (data: any) => void;
|
|
19
|
+
doneAck: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//export interface ClientToServerEvents<isSender extends boolean = false> extends STSClientToServerEvents {
|
|
23
|
+
export interface ClientToServerEvents extends STSDefaultClientToServerEvents {
|
|
24
|
+
subscribe: (data: any) => void;
|
|
25
|
+
unsubscribe: (data: any) => void;
|
|
26
|
+
subscribeKeepAlive: (data: any) => void;
|
|
27
|
+
done: () => void;
|
|
28
|
+
|
|
29
|
+
//compute: (arg: number, callback: (...args: WithTimeoutAck<isSender, [string]>) => void) => void;
|
|
30
|
+
//compute2: (arg: number, callback: (...args: WithTimeoutAck<isSender, [{ data: any}]>) => void) => void;
|
|
31
|
+
compute: (arg: number, callback: (data: string) => void) => void;
|
|
32
|
+
compute2: (arg: number, callback: (data: { data: any}) => void) => void;
|
|
33
|
+
}
|