@nsshunt/stsappframework 3.1.129 → 3.1.131

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 (65) hide show
  1. package/dist/commonTypes.js +2 -2
  2. package/dist/commonTypes.js.map +1 -1
  3. package/dist/ipcMessageHandler.js +4 -2
  4. package/dist/ipcMessageHandler.js.map +1 -1
  5. package/dist/ipcMessageManager.js +32 -4
  6. package/dist/ipcMessageManager.js.map +1 -1
  7. package/dist/ipcMessageProcessorPrimary.js +2 -1
  8. package/dist/ipcMessageProcessorPrimary.js.map +1 -1
  9. package/dist/ipcMessageProcessorWorker.js +2 -1
  10. package/dist/ipcMessageProcessorWorker.js.map +1 -1
  11. package/dist/network.js +2 -3
  12. package/dist/network.js.map +1 -1
  13. package/dist/redisMessageHandler.js +144 -6
  14. package/dist/redisMessageHandler.js.map +1 -1
  15. package/dist/redisMessageHandler.test.js +4 -2
  16. package/dist/redisMessageHandler.test.js.map +1 -1
  17. package/dist/stsTransportWinston.js +2 -2
  18. package/dist/stsTransportWinston.js.map +1 -1
  19. package/dist/tcpserver/appConfig.js +1 -2
  20. package/dist/tcpserver/appConfig.js.map +1 -1
  21. package/dist/testing/app.js +191 -37
  22. package/dist/testing/app.js.map +1 -1
  23. package/dist/testing/appConfig.js +1 -2
  24. package/dist/testing/appConfig.js.map +1 -1
  25. package/dist/vitesttesting/appConfig.js +1 -2
  26. package/dist/vitesttesting/appConfig.js.map +1 -1
  27. package/dist/workerprocessbase.js +107 -0
  28. package/dist/workerprocessbase.js.map +1 -1
  29. package/package.json +13 -13
  30. package/runtest2.sh +1 -1
  31. package/src/ipcMessageHandler.ts +4 -2
  32. package/src/ipcMessageManager.ts +40 -4
  33. package/src/ipcMessageProcessorPrimary.ts +2 -1
  34. package/src/ipcMessageProcessorWorker.ts +2 -1
  35. package/src/redisMessageHandler.test.ts +4 -2
  36. package/src/redisMessageHandler.ts +155 -6
  37. package/src/testing/app.ts +192 -17
  38. package/src/workerprocessbase.ts +123 -2
  39. package/types/authutilsnode.d.ts.map +1 -1
  40. package/types/commonTypes.d.ts +0 -2
  41. package/types/commonTypes.d.ts.map +1 -1
  42. package/types/ipcMessageHandler.d.ts +0 -1
  43. package/types/ipcMessageHandler.d.ts.map +1 -1
  44. package/types/ipcMessageManager.d.ts +1 -0
  45. package/types/ipcMessageManager.d.ts.map +1 -1
  46. package/types/ipcMessageProcessorPrimary.d.ts +0 -1
  47. package/types/ipcMessageProcessorPrimary.d.ts.map +1 -1
  48. package/types/ipcMessageProcessorWorker.d.ts.map +1 -1
  49. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  50. package/types/kafka/kafkaconsumer.d.ts.map +1 -1
  51. package/types/kafka/kafkamanager.d.ts.map +1 -1
  52. package/types/kafka/kafkaproducer.d.ts.map +1 -1
  53. package/types/masterprocessbase.d.ts +0 -4
  54. package/types/masterprocessbase.d.ts.map +1 -1
  55. package/types/middleware/serverNetworkMiddleware.d.ts +0 -1
  56. package/types/middleware/serverNetworkMiddleware.d.ts.map +1 -1
  57. package/types/processbase.d.ts.map +1 -1
  58. package/types/redisMessageHandler.d.ts +2 -1
  59. package/types/redisMessageHandler.d.ts.map +1 -1
  60. package/types/serverprocessbase.d.ts.map +1 -1
  61. package/types/socketIoServerHelper.d.ts.map +1 -1
  62. package/types/testHelpers.d.ts +0 -1
  63. package/types/testHelpers.d.ts.map +1 -1
  64. package/types/workerprocessbase.d.ts +15 -0
  65. package/types/workerprocessbase.d.ts.map +1 -1
@@ -54,7 +54,8 @@ export class IPCMessageHandler extends TinyEmitter {
54
54
  messageReceiverStop: (options: any) => {
55
55
  const worker = (options.worker as Worker);
56
56
  worker.off('message', (payload) => this.#ipcMessageManager?.ProcessMessage(payload, { worker }));
57
- }
57
+ },
58
+ groups: [ ]
58
59
  }
59
60
  this.#ipcMessageManager = new IPCMessageManager(ipcMessageManagerOptions);
60
61
  }
@@ -79,7 +80,8 @@ export class IPCMessageHandler extends TinyEmitter {
79
80
  },
80
81
  messageReceiverStop: (options: any) => {
81
82
  process.off('message', (payload) => this.#ipcMessageManager?.ProcessMessage(payload, options));
82
- }
83
+ },
84
+ groups: [ ]
83
85
  }
84
86
  this.#ipcMessageManager = new IPCMessageManager(ipcMessageManagerOptions);
85
87
  }
@@ -12,6 +12,7 @@ export interface IPCMessageManagerOptions {
12
12
  requestResponseMessageTimeout: number
13
13
  namespace: string
14
14
  role: 'SERVER' | 'CLIENT'
15
+ groups: string[]
15
16
  messageSender: (payload: IIPCMessageProcessorIPCPayload, options: any) => void
16
17
  ProcessRequestMessage: (payload: IIPCMessageProcessorIPCPayload, options: any) => Promise<JSONObject>
17
18
  ProcessResponseMessage?: (reesponses: Record<string, IIPCMessageProcessorIPCPayload>, options: any) => Promise<boolean>
@@ -100,28 +101,43 @@ export class IPCMessageManager
100
101
  }
101
102
 
102
103
  #ProcessMessage = async (msg: any, options: any): Promise<void> => {
104
+ //console.log(chalk.grey(`#ProcessMessage`));
103
105
  if (msg.header && msg.header.localeCompare(this.#messageHeader) === 0) {
104
106
  const message = (msg as IIPCMessageProcessorIPCPayload);
105
107
  if (this.#inflightMessages[message.messageId]) {
106
108
  const inFlightMessageRecord: IIPCMessageProcessorWorkerRecord = this.#inflightMessages[message.messageId];
107
109
  inFlightMessageRecord.responses[message.senderId ] = { ...message };
108
110
  let completed = true; // Defaults to true
111
+
112
+ //console.log(chalk.grey(`#ProcessMessage:2`));
113
+
109
114
  if (this.#options.ProcessResponseMessage) {
115
+
116
+ if (msg.requestPayload.__eventName.localeCompare('ping') !== 0) {
117
+ console.log(chalk.grey(`#ProcessMessage:3: [${JSON.stringify(msg.requestPayload)}]`));
118
+ }
119
+
110
120
  completed = await this.#options.ProcessResponseMessage(inFlightMessageRecord.responses, options);
111
121
  if (completed) {
122
+ //console.log(chalk.grey(`#ProcessMessage:3.1`));
112
123
  inFlightMessageRecord.endTime = performance.now();
113
124
  clearTimeout(inFlightMessageRecord.timeout as NodeJS.Timer);
114
125
  inFlightMessageRecord.callBack({
115
126
  responsePayload: Object.values(inFlightMessageRecord.responses).map(r => r.responsePayload)
116
127
  } as any, options) //
117
128
  delete this.#inflightMessages[message.messageId];
129
+
130
+ //console.log(chalk.grey(`this.#inflightMessages.length = ${Object.keys(this.#inflightMessages).length}`));
118
131
  }
119
132
  } else if (completed) {
133
+ //console.log(chalk.grey(`#ProcessMessage:4`));
120
134
  inFlightMessageRecord.endTime = performance.now();
121
135
  clearTimeout(inFlightMessageRecord.timeout as NodeJS.Timer);
122
136
  inFlightMessageRecord.callBack(message, options) // inFlightMessageRecord.responses
123
137
  //@@inFlightMessageRecord.callBack(Object.values(inFlightMessageRecord.responses), options) //
124
138
  delete this.#inflightMessages[message.messageId];
139
+ } else {
140
+ //console.log(chalk.grey(`#ProcessMessage:5`));
125
141
  }
126
142
  } else {
127
143
  //throw new Error(`Could not find Request/Response message with id: [${message.messageId}]`); //@@
@@ -153,10 +169,30 @@ export class IPCMessageManager
153
169
  if ((msg.header as string).includes(checkName)) {
154
170
  const message = (msg as IIPCMessageProcessorIPCPayload);
155
171
  if (msg.messageType.localeCompare('REQUEST') === 0) {
156
- message.responsePayload = await this.#options.ProcessRequestMessage(message, options);
157
- message.senderId = this.#id;
158
- message.messageType = 'RESPONSE';
159
- this.#options.messageSender(message, options);
172
+ let processMessage = true;
173
+ if (message.requestPayload.args.length > 0 && message.requestPayload.args[0].group) {
174
+ const group = message.requestPayload.args[0].group;
175
+ console.log(chalk.green(`${process.pid}:ProcessMessage(): Processor Options Groups: [${this.#options.groups}] request group: [${group}]`));
176
+ processMessage = (this.#options.groups.indexOf(group) === -1) ? false : true;
177
+ if (processMessage === false) {
178
+ console.log(chalk.red(`${process.pid}:ProcessMessage(): Skipping this message: Not in correct group: [${group}]`));
179
+ } else {
180
+ console.log(chalk.yellow(`${process.pid}:ProcessMessage(): Will process this message: [${group}]`));
181
+ }
182
+ }
183
+
184
+ if (processMessage) {
185
+ message.responsePayload = await this.#options.ProcessRequestMessage(message, options);
186
+ message.senderId = this.#id;
187
+ message.messageType = 'RESPONSE';
188
+
189
+ if (message.requestPayload.__eventName.localeCompare('ping') !== 0) {
190
+ console.log(chalk.grey(`${process.pid}:ProcessMessage(): Sending response: [${JSON.stringify(message.responsePayload)}]`));
191
+ }
192
+
193
+ this.#options.messageSender(message, options);
194
+ }
195
+
160
196
  } else {
161
197
  // Received a response (to my request)
162
198
  this.#ProcessMessage(msg, options);
@@ -42,7 +42,8 @@ export class IPCMessageProcessorPrimary
42
42
  messageReceiverStop: (options: any) => {
43
43
  const worker = (options.worker as Worker);
44
44
  worker.off('message', (payload) => this.#ipcMessageManager.ProcessMessage(payload, { worker }));
45
- }
45
+ },
46
+ groups: [ ]
46
47
  }
47
48
  this.#ipcMessageManager = new IPCMessageManager(ipcMessageManagerOptions);
48
49
  }
@@ -39,7 +39,8 @@ export class IPCMessageProcessorWorker {
39
39
  },
40
40
  messageReceiverStop: (options: any) => {
41
41
  process.off('message', (payload) => this.#ipcMessageManager.ProcessMessage(payload, options));
42
- }
42
+ },
43
+ groups: [ ]
43
44
  }
44
45
  this.#ipcMessageManager = new IPCMessageManager(ipcMessageManagerOptions);
45
46
  }
@@ -39,7 +39,8 @@ describe.skip("Redis Message Handler Test", () =>
39
39
  logger: defaultLogger,
40
40
  role: 'SERVER',
41
41
  redisUrl: ioRedisMessageProcessorUrl, // goptions.imRedisMessageProcessorUrl,
42
- namespace: 'redistestingstsframework'
42
+ namespace: 'redistestingstsframework',
43
+ groups: [ ]
43
44
  });
44
45
  this.#r1.Start();
45
46
 
@@ -87,7 +88,8 @@ describe.skip("Redis Message Handler Test", () =>
87
88
  logger: defaultLogger,
88
89
  role: 'CLIENT',
89
90
  redisUrl: ioRedisMessageProcessorUrl, // goptions.imRedisMessageProcessorUrl,
90
- namespace: 'redistestingstsframework'
91
+ namespace: 'redistestingstsframework',
92
+ groups: [ ]
91
93
  });
92
94
  this.#r1.Start();
93
95
 
@@ -17,6 +17,7 @@ export interface IRedisAdminManagerOptions {
17
17
  logger: ISTSLogger
18
18
  role: 'SERVER' | 'CLIENT'
19
19
  namespace: string
20
+ groups: string[]
20
21
  }
21
22
 
22
23
  export interface IClientRecord {
@@ -24,6 +25,7 @@ export interface IClientRecord {
24
25
  clientConnected: Date
25
26
  pingCount: number
26
27
  timeout: NodeJS.Timeout
28
+ groups: string[]
27
29
  }
28
30
 
29
31
  export interface IEventPayload {
@@ -78,19 +80,33 @@ export class RedisMessageHandler extends TinyEmitter {
78
80
  if (this.#options.role.localeCompare('CLIENT') === 0) {
79
81
  const ping = () => {
80
82
  this.#pingTimeout = setTimeout(() => {
81
- this.emit('ping', this.#ipcMessageManager?.id, (response: any) => { });
83
+ let group = '';
84
+ if (process.pid % 2 === 0) {
85
+ group = 'even';
86
+ } else {
87
+ group = 'odd';
88
+ }
89
+ //console.log(chalk.gray(`${process.pid}: emitting ping ...`))
90
+ this.emit('ping', {
91
+ id: this.#ipcMessageManager?.id,
92
+ groups: [
93
+ group
94
+ ]
95
+ }, (response: any) => { });
82
96
  ping();
83
97
  }, 1000).unref();
84
98
  }
85
99
  ping();
86
100
  } else {
87
- this.on('ping', (id: string, callback: any) => {
101
+ this.on('ping', (pingData: JSONObject, callback: any) => {
102
+ const { id, groups } = pingData;
88
103
  if (this.#clients[id]) {
89
104
  clearTimeout(this.#clients[id].timeout);
90
105
  this.#clients[id].pingCount++;
91
106
  this.#clients[id].timeout = setTimeout(() => {
92
107
  delete this.#clients[id];
93
108
  }, 2000);
109
+ this.#clients[id].groups = groups;
94
110
  } else {
95
111
  this.#clients[id] = {
96
112
  id,
@@ -98,12 +114,17 @@ export class RedisMessageHandler extends TinyEmitter {
98
114
  pingCount: 0,
99
115
  timeout: setTimeout(() => {
100
116
  delete this.#clients[id];
101
- }, 2000)
117
+ }, 2000),
118
+ groups
102
119
  }
103
120
  }
121
+ //console.log(chalk.gray(` ${process.pid}: processed ping ...`))
104
122
  callback('ok');
105
123
  });
106
124
  }
125
+
126
+ console.log(chalk.yellow(`RedisMessageHandler:constructor(): [${JSON.stringify(this.#options.groups)}]`));
127
+
107
128
  }
108
129
 
109
130
  #LogInfo(message: any) {
@@ -126,6 +147,7 @@ export class RedisMessageHandler extends TinyEmitter {
126
147
  namespace: this.#options.namespace,
127
148
  role: this.#options.role,
128
149
  messageSender: this.#messageSender,
150
+ groups: this.#options.groups,
129
151
  // This method is used to calculate if all responses have been received from multiple clients (broadcast)
130
152
  // returns true/false.
131
153
  ProcessResponseMessage: this.#ProcessResponseMessage,
@@ -166,16 +188,143 @@ export class RedisMessageHandler extends TinyEmitter {
166
188
  return allFound;
167
189
  }
168
190
 
191
+ console.log(chalk.grey(`${process.pid}: -->> *** <<-- #ProcessResponseMessage`));
169
192
  let found = true;
193
+
194
+ // Sender role here is SERVER
195
+
196
+ console.log(chalk.yellow(`${process.pid}: Total Clients :-`));
197
+ Object.values(this.#clients).forEach(c => {
198
+ console.log(chalk.yellow(`${process.pid}: ${c.id} ${c.groups}`));
199
+ })
200
+
201
+ let requestGroup = null;
202
+ console.log(chalk.blue(`${process.pid}: Responses :-`));
203
+ for (const [responseId, response] of Object.entries(responses)) {
204
+ console.log(chalk.blue(`${process.pid}: client.id: [${responseId}] response payload: [${JSON.stringify(response.responsePayload)}]`));
205
+ if (response.requestPayload.args.length > 0 && response.requestPayload.args[0].group) {
206
+ requestGroup = response.requestPayload.args[0].group;
207
+ console.log(chalk.blue(`${process.pid}: Group Request: [${requestGroup}]`));
208
+ break;
209
+ }
210
+ }
211
+
212
+ if (requestGroup) {
213
+ console.log(chalk.blue(`${process.pid}: Group Request`));
214
+ const clientsInGroup = Object.values(this.#clients).filter(c => {
215
+ if (c.groups.indexOf(requestGroup) === -1) {
216
+ return false;
217
+ }
218
+ return true;
219
+ });
220
+ console.log(chalk.blue(`${process.pid}: Clients in group: [${requestGroup}] :-`));
221
+ clientsInGroup.forEach(c => {
222
+ console.log(chalk.blue(`${process.pid}: ${c.id}`));
223
+ })
224
+
225
+ // Now make sure that all clients are in the responses
226
+ found = true;
227
+ clientsInGroup.forEach(c => {
228
+ if (!responses[c.id]) {
229
+ found = false;
230
+ }
231
+ })
232
+ console.log(chalk.blue(`${process.pid}: found (group) = [${found}]`));
233
+ } else {
234
+ console.log(chalk.blue(`${process.pid}: Non-Group Request`));
235
+
236
+ const clientsInGroup = Object.values(this.#clients)
237
+ console.log(chalk.blue(`${process.pid}: Clients in group (global list): [${requestGroup}] :-`));
238
+ clientsInGroup.forEach(c => {
239
+ console.log(chalk.blue(`${process.pid}: ${c.id}`));
240
+ })
241
+
242
+ // Now make sure that all clients are in the responses
243
+ found = true;
244
+ clientsInGroup.forEach(c => {
245
+ if (!responses[c.id]) {
246
+ found = false;
247
+ }
248
+ })
249
+ console.log(chalk.blue(`${process.pid}: found (non-group) = [${found}]`));
250
+ }
251
+
252
+ return found;
253
+
254
+
255
+ /*
256
+
257
+
170
258
  Object.values(this.#clients).map(c => {
171
- if (!responses[c.id]) {
172
- found = false;
259
+ if (found) {
260
+ // Check for group payloads
261
+
262
+ console.log(chalk.magenta(`${process.pid}: clients (from ping data)`));
263
+ for (const [key, value] of Object.entries(this.#clients)) {
264
+ console.log(chalk.magenta(`${process.pid}: ${key} = [${value.id} ${value.groups}]`))
265
+ }
266
+ console.log(chalk.blue(`${process.pid}: ${JSON.stringify(responses)}`));
267
+
268
+
269
+ if (responses[c.id]) {
270
+ console.log(chalk.blue(`${process.pid}: 1`));
271
+ if (responses[c.id].requestPayload) {
272
+ console.log(chalk.blue(`${process.pid}: 2`));
273
+ if (responses[c.id].requestPayload.args.length > 0) {
274
+ console.log(chalk.blue(`${process.pid}: 3`));
275
+ if (responses[c.id].requestPayload.args[0].group) {
276
+ console.log(chalk.blue(`${process.pid}: 4`));
277
+ console.log(chalk.magenta(`${process.pid}:requestPayload: [${JSON.stringify(responses[c.id].requestPayload.args[0].group )}]`))
278
+ const requestGroup = responses[c.id].requestPayload.args[0].group;
279
+ //const responseGroup = responses[c.id].responsePayload.args[0].group;
280
+
281
+ console.log(chalk.magenta(`${process.pid}: clients (from ping data)`));
282
+ Object.values(this.#clients).forEach(c => {
283
+ console.log(chalk.magenta(` ${c.groups}`))
284
+ })
285
+ console.log(chalk.magenta(`${process.pid}:`));
286
+
287
+ console.log(chalk.magenta(`${process.pid}: responses so far...`));
288
+
289
+ for (const [key, value] of Object.entries(responses)) {
290
+ console.log(chalk.magenta(`${process.pid}: client.id: [${key}] response payload: [${JSON.stringify(value.responsePayload)}]`));
291
+ }
292
+ console.log(chalk.magenta(`${process.pid}:`));
293
+
294
+ const clientsInGroup = Object.values(this.#clients).filter(c => {
295
+ const foundGroupIndex = c.groups.indexOf(requestGroup);
296
+ if (foundGroupIndex === -1) {
297
+ return false;
298
+ }
299
+ return true;
300
+ });
301
+ clientsInGroup.forEach(c => {
302
+ console.log(`${process.pid}:clientsInGroup: [${c.id}] groups: [${c.groups}]`);
303
+ if (!responses[c.id]) {
304
+ console.log(`${process.pid}: clientsInGroup - not found: [${c.id}]`);
305
+ found = false;
306
+ }
307
+ });
308
+ // Now check if all responses for completed group membership
309
+ }
310
+ }
311
+ }
312
+ } else {
313
+ if (!responses[c.id]) {
314
+ found = false;
315
+ }
316
+ }
173
317
  }
174
318
  });
175
319
 
176
- if (found) {
320
+ console.log(chalk.grey(`${process.pid}: ** Testing condition **`))
321
+ if (found === true) {
322
+ console.log(chalk.green(`${process.pid}:Found all messages - should return results`))
177
323
  return true;
178
324
  }
325
+ console.log(chalk.red(`${process.pid}:did not find all messages (yet) ...`))
326
+ return false;
327
+ */
179
328
  return false;
180
329
  }
181
330
 
@@ -20,6 +20,9 @@ import { v4 as uuidv4 } from 'uuid';
20
20
  import { RedisMessageHandler } from './../redisMessageHandler'
21
21
  import { goptions } from '@nsshunt/stsconfig'
22
22
 
23
+ import si from 'systeminformation' // https://systeminformation.io/
24
+ import { GetFirstNetworkInterface } from './../network'
25
+
23
26
  const sleepVal = 0;
24
27
  const maxLoop = 100;
25
28
 
@@ -177,13 +180,97 @@ const StartTestWorker = () => {
177
180
  }, 1000);
178
181
  }
179
182
 
180
- const iterations = 100;
183
+ const iterations = 0;
181
184
  const delay = 100;
182
185
 
186
+ const GetNumCPUs = async (): Promise<number> => {
187
+ // https://systeminformation.io/
188
+ const valueObject = {
189
+ cpu: '*'
190
+ }
191
+
192
+ const sysinfo = await si.get(valueObject);
193
+ let numCPUs = 2;
194
+ if (goptions.useCPUs > 0) {
195
+ if (goptions.useCPUs >= 1) {
196
+ numCPUs = goptions.useCPUs;
197
+ } else {
198
+ numCPUs = Math.round(sysinfo.cpu.cores * goptions.useCPUs);
199
+ }
200
+ } else {
201
+ numCPUs = sysinfo.cpu.physicalCores;
202
+ }
203
+ return numCPUs;
204
+ }
205
+
206
+ const LogInfoMessage = (message: string) => {
207
+ console.log(message);
208
+ }
209
+
210
+ const LogSystemTelemetry = async () => {
211
+ // https://systeminformation.io/
212
+ const valueObject = {
213
+ system: '*',
214
+ osInfo: '*',
215
+ cpu: '*',
216
+ mem: '*',
217
+ dockerInfo: '*',
218
+ //dockerImages: '*',
219
+ dockerContainers: '*',
220
+ }
221
+
222
+ const sysinfo = await si.get(valueObject);
223
+ const numCPUs = await GetNumCPUs();
224
+ const hostname = sysinfo.osInfo.hostname;
225
+
226
+ const hostaddr = GetFirstNetworkInterface();
227
+ if (hostaddr !== null) {
228
+ LogInfoMessage(`Host Address: ${hostaddr}`);
229
+ } else {
230
+ LogInfoMessage(`Unknown Host Address.`);
231
+ }
232
+ LogInfoMessage(`Server starting with ${numCPUs} Cores/Threads`);
233
+
234
+ LogInfoMessage(`Hostname: ${hostname}`);
235
+ LogInfoMessage(`System: ${JSON.stringify(sysinfo.system)}`);
236
+ LogInfoMessage(`OS Info: ${JSON.stringify(sysinfo.osInfo)}`);
237
+ LogInfoMessage(`CPU: ${JSON.stringify(sysinfo.cpu)}`);
238
+ LogInfoMessage(`Memory: ${JSON.stringify(sysinfo.mem)}`);
239
+
240
+ const promArray: Promise<any>[] = [ ];
241
+
242
+ sysinfo.dockerContainers.forEach((dc: { id: string; }) => {
243
+ LogInfoMessage(dc.id);
244
+ const dcs = promArray.push(si.dockerContainerStats(dc.id));
245
+ console.log(dcs);
246
+ });
247
+ const dockerContainerStats = await Promise.all(promArray);
248
+
249
+ const sysInfo = {
250
+ hostname,
251
+ numCPUs,
252
+ hostaddr,
253
+ system: sysinfo.system,
254
+ osInfo: sysinfo.osInfo,
255
+ cpu: sysinfo.cpu,
256
+ mem: sysinfo.mem,
257
+ dockerInfo: sysinfo.dockerInfo,
258
+ //dockerImages: sysinfo.dockerImages,
259
+ dockerContainers: sysinfo.dockerContainers,
260
+ dockerContainerStats
261
+ }
262
+
263
+ console.log(sysInfo);
264
+
265
+ console.log(JSON.stringify(sysInfo));
266
+ }
267
+
183
268
  if (cluster.isPrimary) {
184
269
  new MasterProcessBase(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
185
270
  //StartTestPrimary();
186
271
 
272
+ LogSystemTelemetry();
273
+
187
274
  setTimeout(() => {
188
275
  const p: Record<string, IPCMessageHandler> = { };
189
276
  /*
@@ -206,7 +293,76 @@ if (cluster.isPrimary) {
206
293
  }
207
294
  */
208
295
 
296
+ /*
297
+ const stsServiceControl: RedisMessageHandler = new RedisMessageHandler({
298
+ logger: defaultLogger,
299
+ role: 'SERVER',
300
+ redisUrl: goptions.imRedisMessageProcessorUrl,
301
+ namespace: 'stsServiceControl',
302
+ groups: [ ]
303
+ });
304
+ stsServiceControl.Start();
305
+
306
+ stsServiceControl.on('ping_ex', (pingData: JSONObject, callback: any) => {
307
+ console.log(chalk.yellow(`${process.pid}: stsServiceControl.on(ping): [${JSON.stringify(pingData)}]`));
308
+ callback({pingData, dateTime: new Date().getTime()})
309
+ });
310
+
311
+ setInterval(() => {
312
+ stsServiceControl.emit('GET_SYSTEM_TELEMETRY', { }, (response: any) => {
313
+ console.log(chalk.green(` ==>> ${process.pid}: Response(GET_SYSTEM_TELEMETRY): [${JSON.stringify(response)}]`));
314
+ });
315
+ }, 5000);
316
+ */
317
+
318
+
319
+
320
+ const r1: RedisMessageHandler = new RedisMessageHandler({
321
+ logger: defaultLogger,
322
+ role: 'SERVER',
323
+ redisUrl: goptions.imRedisMessageProcessorUrl,
324
+ namespace: 'mytestapp',
325
+ groups: [ ]
326
+ });
327
+ r1.Start();
328
+
329
+
330
+
331
+ let i = 0;
332
+ let group = '';
333
+ const xxx = () => {
334
+ setTimeout(() => {
335
+
336
+ i++;
337
+
338
+ if (i % 2 === 0) {
339
+ group = 'even'
340
+ } else {
341
+ group = 'odd'
342
+ }
343
+
344
+ const emitobj = { group, i: i, a: 'a', b: 'b' };
345
+ r1.emit('fromprimaryredis', emitobj, (response: any) => {
346
+ console.log(chalk.cyan(`${process.pid}: Response(fromprimaryredis): [${JSON.stringify(response)}]`));
347
+ });
348
+
349
+ /*
350
+ const globalemitobj = { i: i, a: 'a', b: 'b' };
351
+ r1.emit('globalmessage', globalemitobj, (response: any) => {
352
+ console.log(chalk.cyan(`${process.pid}: Response(globalmessage): [${JSON.stringify(response)}]`));
353
+ });
354
+ */
355
+
356
+ //xxx();
357
+ }, 2000);
358
+ }
359
+ xxx();
360
+
361
+
362
+
363
+
209
364
 
365
+ /*
210
366
  const r1: RedisMessageHandler = new RedisMessageHandler({
211
367
  logger: defaultLogger,
212
368
  role: 'SERVER',
@@ -224,16 +380,6 @@ if (cluster.isPrimary) {
224
380
 
225
381
  setTimeout(async () => {
226
382
  for (let i=0; i < iterations; i++) {
227
- /*
228
- Object.keys(p).forEach(async (pKey) => {
229
- const emitobj = { i: i, a: 'a', b: 'b', worker: pKey };
230
- console.log(chalk.green(`${process.pid}: emit event to worker: [${pKey}] fromprimary: [${JSON.stringify(emitobj)}`));
231
- p[pKey].emit('fromprimary', emitobj, (response: any) => {
232
- console.log(chalk.green(`${process.pid}: ${JSON.stringify(response)}`));
233
- });
234
- });
235
- */
236
-
237
383
 
238
384
  const emitobj = { i: i, a: 'a', b: 'b' };
239
385
  console.log(chalk.cyan(`${process.pid}: emit event fromprimaryredis fromprimary: [${JSON.stringify(emitobj)}`));
@@ -245,12 +391,45 @@ if (cluster.isPrimary) {
245
391
  }
246
392
 
247
393
  }, 1000);
394
+ */
248
395
  }, 1000);
249
396
  } else {
250
397
  new WorkerProcess(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
251
398
  //StartTestWorker();
252
399
 
253
400
  setTimeout(async () => {
401
+
402
+ let group = '';
403
+ if (process.pid % 2 === 0) {
404
+ group = 'even'
405
+ } else {
406
+ group = 'odd'
407
+ }
408
+
409
+ const r1: RedisMessageHandler = new RedisMessageHandler({
410
+ logger: defaultLogger,
411
+ role: 'CLIENT',
412
+ redisUrl: goptions.imRedisMessageProcessorUrl,
413
+ namespace: 'mytestapp',
414
+ groups: [ group ]
415
+ });
416
+ r1.Start();
417
+
418
+ r1.on('fromprimaryredis', (arg1: JSONObject, callback: any) => {
419
+ console.log(chalk.greenBright(` -->> ${process.pid}: fromprimaryredis.ON: [${JSON.stringify(arg1)}]`));
420
+ callback( {
421
+ status: `PID: [${process.pid}]: response message from event = fromprimaryredis with args ${JSON.stringify(arg1)}`
422
+ })
423
+ });
424
+
425
+ r1.on('globalmessage', (arg1: JSONObject, callback: any) => {
426
+ console.log(chalk.greenBright(` -->> ${process.pid}: globalmessage.ON: [${JSON.stringify(arg1)}]`));
427
+ callback( {
428
+ status: `PID: [${process.pid}]: response message from event = globalmessage with args ${JSON.stringify(arg1)}`
429
+ })
430
+ });
431
+
432
+
254
433
  /*
255
434
  const w1: IPCMessageHandler = new IPCMessageHandler({
256
435
  logger: defaultLogger,
@@ -265,6 +444,7 @@ if (cluster.isPrimary) {
265
444
  });
266
445
  */
267
446
 
447
+ /*
268
448
  const r1: RedisMessageHandler = new RedisMessageHandler({
269
449
  logger: defaultLogger,
270
450
  role: 'CLIENT',
@@ -282,12 +462,6 @@ if (cluster.isPrimary) {
282
462
  setTimeout(async () => {
283
463
  for (let i=0; i < iterations; i++) {
284
464
  const id = uuidv4();
285
- /*
286
- console.log(chalk.yellow(`${process.pid}: emit event fromworker: [${id} ${i} Hello]`));
287
- w1.emit('fromworker', id, i, 'Hello', (response: any) => {
288
- console.log(chalk.yellow(`${process.pid}: ${JSON.stringify(response)}`));
289
- });
290
- */
291
465
 
292
466
  console.log(chalk.green(`${process.pid}: emit event fromworkerredis: [${id} ${i} Hello]`));
293
467
  r1.emit('fromworkerredis', id, i, 'Hello', (response: any) => {
@@ -296,5 +470,6 @@ if (cluster.isPrimary) {
296
470
  await Sleep(delay);
297
471
  }
298
472
  }, 1000);
473
+ */
299
474
  }, 1000);
300
475
  }