@nsshunt/stsappframework 3.0.141 → 3.0.143
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/dist/instrumentationsubscriber.js +53 -29
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +51 -25
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafka/kafkaconsumer.js +20 -12
- package/dist/kafka/kafkaconsumer.js.map +1 -1
- package/dist/kafka/kafkamanager.js +6 -2
- package/dist/kafka/kafkamanager.js.map +1 -1
- package/dist/kafka/kafkaproducer.js +20 -10
- package/dist/kafka/kafkaproducer.js.map +1 -1
- package/dist/kafkatesting/consume.js +27 -7
- package/dist/kafkatesting/consume.js.map +1 -1
- package/dist/kafkatesting/produce.js +15 -9
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/publishertransports/publishTransportDirect.js +10 -2
- package/dist/publishertransports/publishTransportDirect.js.map +1 -1
- package/dist/testing/app.js +19 -0
- package/dist/testing/app.js.map +1 -1
- package/package.json +1 -1
- package/src/commonTypes.ts +5 -5
- package/src/instrumentationsubscriber.ts +57 -29
- package/src/kafka/IMKafkaManager.ts +52 -24
- package/src/kafka/kafkaconsumer.ts +22 -12
- package/src/kafka/kafkamanager.ts +7 -2
- package/src/kafka/kafkaproducer.ts +22 -10
- package/src/kafkatesting/consume.ts +27 -7
- package/src/kafkatesting/produce.ts +15 -9
- package/src/publishertransports/publishTransportDirect.ts +9 -3
- package/src/testing/app.ts +21 -0
- package/types/commonTypes.d.ts +5 -5
- package/types/commonTypes.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts +3 -3
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/kafka/kafkaconsumer.d.ts +5 -5
- package/types/kafka/kafkaconsumer.d.ts.map +1 -1
- package/types/kafka/kafkamanager.d.ts +1 -1
- package/types/kafka/kafkamanager.d.ts.map +1 -1
- package/types/kafka/kafkaproducer.d.ts +4 -4
- package/types/kafka/kafkaproducer.d.ts.map +1 -1
- package/types/publishertransports/publishTransportDirect.d.ts.map +1 -1
|
@@ -18,8 +18,12 @@ const km = new kafkamanager_1.KafkaManager({
|
|
|
18
18
|
const runme = async () => {
|
|
19
19
|
const fromBeginning = false;
|
|
20
20
|
const consumer = km.CreateConsumer(config_1.GROUP_ID + process.env.GROUP_ID);
|
|
21
|
-
await consumer.Connect()
|
|
22
|
-
|
|
21
|
+
await consumer.Connect((error) => {
|
|
22
|
+
console.error(`Connect(): Error: [${error}]`);
|
|
23
|
+
});
|
|
24
|
+
await consumer.Subscribe([config_1.TOPIC], fromBeginning, (error) => {
|
|
25
|
+
console.error(`Subscribe(): Error: [${error}]`);
|
|
26
|
+
});
|
|
23
27
|
await consumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
24
28
|
console.log({
|
|
25
29
|
key,
|
|
@@ -27,9 +31,15 @@ const runme = async () => {
|
|
|
27
31
|
value,
|
|
28
32
|
headers
|
|
29
33
|
});
|
|
34
|
+
}, (error) => {
|
|
35
|
+
console.error(`StartConsumingMessages(): Error: [${error}]`);
|
|
36
|
+
});
|
|
37
|
+
await consumer.Stop((error) => {
|
|
38
|
+
console.error(`Stop(): Error: [${error}]`);
|
|
39
|
+
});
|
|
40
|
+
await consumer.Subscribe(['zzz'], fromBeginning, (error) => {
|
|
41
|
+
console.error(`Subscribe(): Error: [${error}]`);
|
|
30
42
|
});
|
|
31
|
-
await consumer.Stop();
|
|
32
|
-
await consumer.Subscribe(['zzz'], fromBeginning);
|
|
33
43
|
await consumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
34
44
|
console.log({
|
|
35
45
|
key,
|
|
@@ -37,9 +47,15 @@ const runme = async () => {
|
|
|
37
47
|
value,
|
|
38
48
|
headers
|
|
39
49
|
});
|
|
50
|
+
}, (error) => {
|
|
51
|
+
console.error(`StartConsumingMessages(): Error: [${error}]`);
|
|
52
|
+
});
|
|
53
|
+
await consumer.Stop((error) => {
|
|
54
|
+
console.error(`Stop(): Error: [${error}]`);
|
|
55
|
+
});
|
|
56
|
+
await consumer.Subscribe(['yyy'], fromBeginning, (error) => {
|
|
57
|
+
console.error(`Subscribe(): Error: [${error}]`);
|
|
40
58
|
});
|
|
41
|
-
await consumer.Stop();
|
|
42
|
-
await consumer.Subscribe(['yyy'], fromBeginning);
|
|
43
59
|
await consumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
44
60
|
/*
|
|
45
61
|
console.log({
|
|
@@ -50,11 +66,15 @@ const runme = async () => {
|
|
|
50
66
|
});
|
|
51
67
|
*/
|
|
52
68
|
console.log(`key: [${key}] value: [${value}] partition: [${partition}] headers: [${headers}]`);
|
|
69
|
+
}, (error) => {
|
|
70
|
+
console.error(`StartConsumingMessages(): Error: [${error}]`);
|
|
53
71
|
});
|
|
54
72
|
//await km.Subscribe(['zzz'], cb);
|
|
55
73
|
process.on("SIGINT", async () => {
|
|
56
74
|
console.log('=========SIGTERM START =======================');
|
|
57
|
-
await consumer.Disconnect()
|
|
75
|
+
await consumer.Disconnect((error) => {
|
|
76
|
+
console.error(`Disconnect(): Error: [${error}]`);
|
|
77
|
+
});
|
|
58
78
|
console.log('=========SIGTERM END =======================');
|
|
59
79
|
process.exit();
|
|
60
80
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consume.js","sourceRoot":"","sources":["../../src/kafkatesting/consume.ts"],"names":[],"mappings":";;AAAA,iDAAiD,CAAE,UAAU;AAC7D,qCAAuE;AAEvE,0DAAsD;AAGtD,KAAK,UAAU,KAAK,CAAC,YAAY,GAAG,IAAI;IACpC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;AACpE,CAAC;AAED,MAAM,EAAE,GAAG,IAAI,2BAAY,CAAC;IACxB,QAAQ,EAAE,kBAAS,GAAG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AAC,SAAS,GAAG,SAAS,EAAE,CAAC,CAAC;QACrC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;AACL,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BE;AAEF,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -72,16 +72,16 @@ const km = new kafkamanager_1.KafkaManager({
|
|
|
72
72
|
useSSL: false
|
|
73
73
|
});
|
|
74
74
|
const runme = async () => {
|
|
75
|
-
await km.CreateTopic(config_1.TOPIC, config_1.PARTITIONS);
|
|
76
|
-
await km.CreateTopic('zzz', 1);
|
|
77
|
-
await km.CreateTopic('yyy', 1);
|
|
75
|
+
await km.CreateTopic(config_1.TOPIC, config_1.PARTITIONS, (error) => console.log(`CreateTopic: Error: [${error}]`));
|
|
76
|
+
await km.CreateTopic('zzz', 1, (error) => console.log(`CreateTopic: Error: [${error}]`));
|
|
77
|
+
await km.CreateTopic('yyy', 1, (error) => console.log(`CreateTopic: Error: [${error}]`));
|
|
78
78
|
const producer = km.CreateProducer();
|
|
79
|
-
await producer.Connect();
|
|
79
|
+
await producer.Connect((error) => console.log(`Connect: Error: [${error}]`));
|
|
80
80
|
const count = 100000;
|
|
81
81
|
const sleepTime = 1000;
|
|
82
82
|
process.on("SIGINT", async () => {
|
|
83
83
|
console.log('=========SIGTERM START =======================');
|
|
84
|
-
await producer.Disconnect();
|
|
84
|
+
await producer.Disconnect((error) => console.log(`Disconnect: Error: [${error}]`));
|
|
85
85
|
console.log('=========SIGTERM END =======================');
|
|
86
86
|
process.exit();
|
|
87
87
|
});
|
|
@@ -94,13 +94,19 @@ const runme = async () => {
|
|
|
94
94
|
{ key: 'key3', value: 'hey hey! -3' },
|
|
95
95
|
{ key: 'key4', value: 'hey hey! -4' },
|
|
96
96
|
{ key: 'key5', value: 'hey hey! -5' }
|
|
97
|
-
])
|
|
97
|
+
], (error) => {
|
|
98
|
+
console.error(error);
|
|
99
|
+
});
|
|
98
100
|
await producer.SendMessages('zzz', [
|
|
99
101
|
{ key: 'key-zzz', value: chalk_1.default.yellow(`hello world - ${i}`) }
|
|
100
|
-
])
|
|
102
|
+
], (error) => {
|
|
103
|
+
console.error(error);
|
|
104
|
+
});
|
|
101
105
|
await producer.SendMessages('yyy', [
|
|
102
106
|
{ key: 'key-yyy', value: chalk_1.default.cyan(`hello world - ${i}`) }
|
|
103
|
-
])
|
|
107
|
+
], (error) => {
|
|
108
|
+
console.error(error);
|
|
109
|
+
});
|
|
104
110
|
if (i % 100 === 0) {
|
|
105
111
|
console.log(retVal);
|
|
106
112
|
console.log(` ------------=================> ${i}`);
|
|
@@ -109,7 +115,7 @@ const runme = async () => {
|
|
|
109
115
|
await Sleep(sleepTime);
|
|
110
116
|
}
|
|
111
117
|
}
|
|
112
|
-
await producer.Disconnect();
|
|
118
|
+
await producer.Disconnect((error) => console.log(`Disconnect: Error: [${error}]`));
|
|
113
119
|
};
|
|
114
120
|
/*
|
|
115
121
|
const errorTypes = ['unhandledRejection', 'uncaughtException']
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"produce.js","sourceRoot":"","sources":["../../src/kafkatesting/produce.ts"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDE;AACF,qCAAyE;AAEzE,0DAAsD;AAEtD,kBAAe;AAEf,kDAA0B;AAE1B,KAAK,UAAU,KAAK,CAAC,YAAY,GAAG,IAAI;IACpC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;AACpE,CAAC;AAED,MAAM,EAAE,GAAG,IAAI,2BAAY,CAAC;IACxB,QAAQ,EAAE,kBAAS,GAAG,O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,KAAK,GAAG,CAAC,CAAC,CAAC;AACvF,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;EAyBE;AAEF,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
exports.PublishTransportDirect = void 0;
|
|
5
8
|
const IMKafkaManager_1 = require("./../kafka/IMKafkaManager");
|
|
6
9
|
const influxDBManager_1 = require("./../influxdb/influxDBManager");
|
|
7
10
|
const publishTransportUtils_1 = require("./publishTransportUtils");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
12
|
class PublishTransportDirect {
|
|
9
13
|
#influxDBManager;
|
|
10
14
|
#IMkafkaManager;
|
|
11
15
|
constructor() {
|
|
12
16
|
this.#influxDBManager = new influxDBManager_1.InfluxDBManager();
|
|
13
17
|
this.#IMkafkaManager = new IMKafkaManager_1.IMKafkaManager();
|
|
14
|
-
this.#IMkafkaManager.Start()
|
|
18
|
+
this.#IMkafkaManager.Start((error) => {
|
|
19
|
+
console.error(chalk_1.default.red(`${process.pid}:PublishTransportDirect:constructor(): Error during IMkafkaManager.Start: [${error}]`));
|
|
20
|
+
});
|
|
15
21
|
}
|
|
16
22
|
// Returns true for success or false for failure.
|
|
17
23
|
Publish = async (payload) => {
|
|
@@ -20,7 +26,9 @@ class PublishTransportDirect {
|
|
|
20
26
|
payload.context = updatedContext;
|
|
21
27
|
//this.#SendIPCMessageToMaster(InstrumentManagerEventName.UPDATE_INSTRUMENT_DATA, instrumentPayload)
|
|
22
28
|
this.#influxDBManager.OutputInfluxDB(payload);
|
|
23
|
-
this.#IMkafkaManager.OutputLogs(payload)
|
|
29
|
+
this.#IMkafkaManager.OutputLogs(payload, (error) => {
|
|
30
|
+
console.error(chalk_1.default.red(`${process.pid}:PublishTransportDirect:Publish(): Error during IMkafkaManager.OutputLogs: [${error}]`));
|
|
31
|
+
});
|
|
24
32
|
return true;
|
|
25
33
|
}
|
|
26
34
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publishTransportDirect.js","sourceRoot":"","sources":["../../src/publishertransports/publishTransportDirect.ts"],"names":[],"mappings":";AAAA,wFAAwF,CAAE,UAAU
|
|
1
|
+
{"version":3,"file":"publishTransportDirect.js","sourceRoot":"","sources":["../../src/publishertransports/publishTransportDirect.ts"],"names":[],"mappings":";AAAA,wFAAwF,CAAE,UAAU;;;;;;AAMpG,8DAA0D;AAC1D,mEAA+D;AAE/D,mEAA+D;AAE/D,kDAA0B;AAE1B,MAAa,sBAAsB;IAE/B,gBAAgB,CAAkB;IAClC,eAAe,CAAiB;IAEhC;QAEI,IAAI,CAAC,gBAAgB,GAAG,IAAI,iCAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,eAAe,GAAG,IAAI,+BAAc,EAAE,CAAC;QAC5C,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACjC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,8EAA8E,KAAK,GAAG,CAAC,CAAC,CAAC;QACnI,CAAC,CAAC,CAAC;IACP,CAAC;IAED,iDAAiD;IACjD,OAAO,GAAG,KAAK,EAAE,OAA2B,EAAoB,EAAE;QAE9D,IAAI,CAAC;YACD,MAAM,cAAc,GAAG,6CAAqB,CAAC,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACpF,OAAO,CAAC,OAAO,GAAG,cAAqB,CAAC;YAExC,oGAAoG;YACpG,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC/C,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,+EAA+E,KAAK,GAAG,CAAC,CAAC,CAAC;YACpI,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EACd,CAAC;YACG,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC,CAAA;IAED,KAAK,CAAC,KAAK;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AArCD,wDAqCC"}
|
package/dist/testing/app.js
CHANGED
|
@@ -12,6 +12,25 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
12
12
|
//const pid = process.pid;
|
|
13
13
|
const pid = 523552;
|
|
14
14
|
const filePath = `/proc/${pid}/net/dev`;
|
|
15
|
+
/*
|
|
16
|
+
async function testError() {
|
|
17
|
+
throw new Error('some error')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function testtheerror() {
|
|
21
|
+
try {
|
|
22
|
+
await testError();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(`Error2: [${error}]`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
(async () => {
|
|
29
|
+
testtheerror();
|
|
30
|
+
await Sleep(1000);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
})();
|
|
33
|
+
*/
|
|
15
34
|
function getNetworkUsage() {
|
|
16
35
|
try {
|
|
17
36
|
// Read the contents of the /proc/[pid]/net/dev file
|
package/dist/testing/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/testing/app.ts"],"names":[],"mappings":";AAAA,wFAAwF,CAAE,UAAU;;;;;AAEpG,2CAAkD;AAClD,4BAAwC;AACxC,iDAA8C;AAE9C,sDAA8B;AAM9B,sDAAwB;
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/testing/app.ts"],"names":[],"mappings":";AAAA,wFAAwF,CAAE,UAAU;;;;;AAEpG,2CAAkD;AAClD,4BAAwC;AACxC,iDAA8C;AAE9C,sDAA8B;AAM9B,sDAAwB;AAMxB,0BAA0B;AAC1B,MAAM,GAAG,GAAG,MAAM,CAAA;AAElB,MAAM,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;EAkBE;AAEF,SAAS,eAAe;IACpB,IAAI,CAAC;QACD,oDAAoD;QACpD,MAAM,OAAO,GAAG,iBAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAElD,sDAAsD;QACtD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAE5D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAElB,2FAA2F;QAC3F,6CAA6C;QAC7C,8CAA8C;QAE9C,oCAAoC;QACpC;;;;QAIA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;AACL,CAAC;AAED,IAAI,iBAAO,CAAC,SAAS,EAAE,CAAC;IACpB,IAAI,qBAAiB,CAAC,IAAA,gCAAoB,EAAC,IAAI,EAAE,iBAAO,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAEnF,WAAW,CAAC;QACR;;;;UAIE;QAEF,eAAe,EAAE,CAAA;QAEjB,0BAA0B;QAE1B,mBAAmB;IAEvB,CAAC,EAAE,IAAI,CAAC,CAAA;AAEZ,CAAC;KAAM,CAAC;IACJ,IAAI,4BAAa,CAAC,IAAA,gCAAoB,EAAC,IAAI,EAAE,iBAAO,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACnF,CAAC"}
|
package/package.json
CHANGED
package/src/commonTypes.ts
CHANGED
|
@@ -228,11 +228,11 @@ export interface InstrumentPayload {
|
|
|
228
228
|
export interface IKafkaConsumer {
|
|
229
229
|
get consumer(): Consumer
|
|
230
230
|
get id(): string
|
|
231
|
-
Connect(): Promise<void>
|
|
232
|
-
Disconnect(): Promise<void>
|
|
233
|
-
Subscribe: (topics: string[], fromBeginning: boolean) => Promise<void>
|
|
234
|
-
Stop: () => Promise<void>
|
|
235
|
-
StartConsumingMessages: (cb: (topic: string, key: string, partition: number, value: string, headers: IHeaders | undefined) => void) => Promise<void>
|
|
231
|
+
Connect(errorCb: (error: any) => void): Promise<void>
|
|
232
|
+
Disconnect(errorCb: (error: any) => void): Promise<void>
|
|
233
|
+
Subscribe: (topics: string[], fromBeginning: boolean, errorCb: (error: any) => void) => Promise<void>
|
|
234
|
+
Stop: (errorCb: (error: any) => void) => Promise<void>
|
|
235
|
+
StartConsumingMessages: (cb: (topic: string, key: string, partition: number, value: string, headers: IHeaders | undefined) => void, errorCb: (error: any) => void) => Promise<void>
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export type logFunction = (msg: any) => void
|
|
@@ -91,8 +91,15 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
91
91
|
if (kafka) {
|
|
92
92
|
// Un-Subscribe from this kafka topic
|
|
93
93
|
this.#Log(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`));
|
|
94
|
-
|
|
95
|
-
await kafka.kafkaConsumer?.
|
|
94
|
+
|
|
95
|
+
await kafka.kafkaConsumer?.Stop((error) => {
|
|
96
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Stop Error: [${error}]`));
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await kafka.kafkaConsumer?.Disconnect((error) => {
|
|
100
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Disconnect Error: [${error}]`));
|
|
101
|
+
});
|
|
102
|
+
|
|
96
103
|
this.#Log(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`));
|
|
97
104
|
} else {
|
|
98
105
|
this.#Log(chalk.magenta(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`));
|
|
@@ -117,35 +124,56 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
117
124
|
this.#Log(chalk.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${subscription.kafka.kafkaTopic}] Starting`));
|
|
118
125
|
|
|
119
126
|
const kafka = subscription.kafka;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
|
|
128
|
+
let connectError = false;
|
|
129
|
+
await kafka.kafkaConsumer.Connect((error) => {
|
|
130
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Connect: Error: [${error}]`));
|
|
131
|
+
connectError = true;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (!connectError) {
|
|
135
|
+
let subscribeError = false;
|
|
136
|
+
await kafka.kafkaConsumer.Subscribe([kafka.kafkaTopic], subscription.kafka.kafkaFromBeginning, (error) => {
|
|
137
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Subscribe: Error: [${error}]`));
|
|
138
|
+
subscribeError = true;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (!subscribeError) {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
|
+
await kafka.kafkaConsumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
144
|
+
try {
|
|
145
|
+
if (key != "" && value != "") {
|
|
146
|
+
if (topic.localeCompare(key) === 0) {
|
|
147
|
+
subscription.cb({
|
|
148
|
+
subscriptionKey: subscription.subscriptionKey,// Original requested topic (may be kafka un-safe)
|
|
149
|
+
data: {
|
|
150
|
+
kafkaTopic: kafka.kafkaTopic, // Safe kafka topic key with prefix. kafkaTopic, topic and key should be same value
|
|
151
|
+
kafkaGroupId: kafka.kafkaGroupId,
|
|
152
|
+
partition,
|
|
153
|
+
topic, // kafkaTopic, topic and key should be same value
|
|
154
|
+
key, // kafkaTopic, topic and key should be same value
|
|
155
|
+
value
|
|
156
|
+
} as IKafkaData
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`));
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`));
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`));
|
|
140
166
|
}
|
|
141
|
-
}
|
|
142
|
-
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka():
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
}, (error) => {
|
|
168
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.StartConsumingMessages: Error: [${error}]`));
|
|
169
|
+
});
|
|
170
|
+
this.#Log(chalk.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`));
|
|
171
|
+
} else {
|
|
172
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not subscribe to topic, StartConsumingMessages aborted.`));
|
|
146
173
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
174
|
+
} else {
|
|
175
|
+
this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not connect to topic, subscribe aborted.`));
|
|
176
|
+
}
|
|
149
177
|
} else {
|
|
150
178
|
this.#Log(chalk.magenta(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`));
|
|
151
179
|
}
|
|
@@ -51,45 +51,61 @@ export class IMKafkaManager {
|
|
|
51
51
|
this.#km = new KafkaManager(kmc);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
#RaiseError = (msg: string, errorCb: (error: any) => void) => {
|
|
55
|
+
console.error(chalk.red(msg));
|
|
56
|
+
errorCb(msg);
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
get km(): KafkaManager {
|
|
55
60
|
return this.#km;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
Start = async (): Promise<void> => {
|
|
63
|
+
Start = async (errorCb: (error: any) => void): Promise<void> => {
|
|
59
64
|
this.#producer = this.#km.CreateProducer();
|
|
60
|
-
await this.#producer.Connect()
|
|
65
|
+
await this.#producer.Connect((error) => {
|
|
66
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:Start(): Error: [${error}]`, errorCb);
|
|
67
|
+
});
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
Terminate = async (): Promise<void> => {
|
|
70
|
+
Terminate = async (errorCb: (error: any) => void): Promise<void> => {
|
|
64
71
|
try {
|
|
65
72
|
if (this.#shuttingDown) {
|
|
66
|
-
debug(chalk.yellow(
|
|
73
|
+
debug(chalk.yellow(`${process.pid}:IMKafkaManager:Terminate: Terminate already called. Ignoring.`));
|
|
67
74
|
} else {
|
|
68
75
|
this.#shuttingDown = true;
|
|
69
|
-
debug(chalk.yellow(
|
|
76
|
+
debug(chalk.yellow(`${process.pid}:ProducerDisconnect`));
|
|
70
77
|
if (this.#producer) {
|
|
71
|
-
await this.#producer.Disconnect()
|
|
78
|
+
await this.#producer.Disconnect((error) => {
|
|
79
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error in producer.Disconnect: [${error}]`, errorCb);
|
|
80
|
+
});
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
} catch (error) {
|
|
75
|
-
|
|
84
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error: [${error}]`, errorCb);
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
async #OutputLogsToKafkaTopic(topic: string, logMessages: string[]) {
|
|
88
|
+
async #OutputLogsToKafkaTopic(topic: string, logMessages: string[], errorCb: (error: any) => void) {
|
|
80
89
|
try {
|
|
81
90
|
if (!this.#topics[topic]) {
|
|
82
|
-
debug(chalk.yellow(
|
|
91
|
+
debug(chalk.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Starting`));
|
|
83
92
|
this.#topics[topic] = true;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
|
|
94
|
+
let createTopicError = false;
|
|
95
|
+
const result = await this.#km.CreateTopic(topic, 1, (error) => {
|
|
96
|
+
createTopicError = true;
|
|
97
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Error in km.CreateTopic: [${error}]`, errorCb);
|
|
98
|
+
});
|
|
99
|
+
if (!createTopicError) {
|
|
100
|
+
if (result) {
|
|
101
|
+
debug(chalk.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed`));
|
|
102
|
+
} else {
|
|
103
|
+
debug(chalk.cyan(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed - topic already exists`));
|
|
104
|
+
}
|
|
89
105
|
}
|
|
90
106
|
}
|
|
91
107
|
} catch (error) {
|
|
92
|
-
|
|
108
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error: [${error}]`, errorCb);
|
|
93
109
|
return;
|
|
94
110
|
}
|
|
95
111
|
|
|
@@ -101,14 +117,16 @@ export class IMKafkaManager {
|
|
|
101
117
|
|
|
102
118
|
// Don't wait for these to return ...
|
|
103
119
|
if (this.#producer) {
|
|
104
|
-
this.#producer.SendMessages(topic, messages as any)
|
|
120
|
+
this.#producer.SendMessages(topic, messages as any, (error) => {
|
|
121
|
+
console.error(chalk.red(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages: [${error}]`));
|
|
122
|
+
});
|
|
105
123
|
}
|
|
106
124
|
} catch (error) {
|
|
107
|
-
|
|
125
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages (2): [${error}]`, errorCb);
|
|
108
126
|
}
|
|
109
127
|
}
|
|
110
128
|
|
|
111
|
-
async OutputLogs(instrumentPayload: InstrumentPayload): Promise<boolean> {
|
|
129
|
+
async OutputLogs(instrumentPayload: InstrumentPayload, errorCb: (error: any) => void): Promise<boolean> {
|
|
112
130
|
try {
|
|
113
131
|
if (this.#shuttingDown) {
|
|
114
132
|
return false;
|
|
@@ -126,17 +144,23 @@ export class IMKafkaManager {
|
|
|
126
144
|
if (agentName && threadId && asyncRunnerId) {
|
|
127
145
|
// Output logs for a specific asyncRunnerId
|
|
128
146
|
topic = `${KAFKA_PREFIX}_${agentName}_${threadId}_${asyncRunnerId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
129
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages)
|
|
147
|
+
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
148
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId && asyncRunnerId): [${error}]`, errorCb);
|
|
149
|
+
});
|
|
130
150
|
}
|
|
131
151
|
if (agentName && threadId) {
|
|
132
152
|
// Output logs for a specific thread (worker) within an agent
|
|
133
153
|
topic = `${KAFKA_PREFIX}_${agentName}_${threadId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
134
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages)
|
|
154
|
+
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
155
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId): [${error}]`, errorCb);
|
|
156
|
+
});
|
|
135
157
|
}
|
|
136
158
|
if (agentName) {
|
|
137
159
|
// Output logs for a specific thread (worker) within an agent
|
|
138
160
|
topic = `${KAFKA_PREFIX}_${agentName}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
139
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages)
|
|
161
|
+
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
162
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName): [${error}]`, errorCb);
|
|
163
|
+
});
|
|
140
164
|
}
|
|
141
165
|
} else {
|
|
142
166
|
// Processing service payload
|
|
@@ -144,12 +168,16 @@ export class IMKafkaManager {
|
|
|
144
168
|
if (serviceInstanceId && serviceInstanceProcessId && pid && ppid) {
|
|
145
169
|
// Output to the specific thread within an instance
|
|
146
170
|
topic = `${KAFKA_PREFIX}_${serviceInstanceId}_${serviceInstanceProcessId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
147
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages)
|
|
171
|
+
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
172
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (serviceInstanceId && serviceInstanceProcessId && pid && ppid): [${error}]`, errorCb);
|
|
173
|
+
});
|
|
148
174
|
|
|
149
175
|
if (pid === ppid) {
|
|
150
176
|
// Output only to the main thread on the service, i.e. this is for O/A service logging
|
|
151
177
|
topic = `${KAFKA_PREFIX}_${serviceInstanceId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
152
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages)
|
|
178
|
+
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
179
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (pid === ppid): [${error}]`, errorCb);
|
|
180
|
+
});
|
|
153
181
|
}
|
|
154
182
|
}
|
|
155
183
|
}
|
|
@@ -157,7 +185,7 @@ export class IMKafkaManager {
|
|
|
157
185
|
}
|
|
158
186
|
return true;
|
|
159
187
|
} catch (error: any) {
|
|
160
|
-
|
|
188
|
+
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Error: [${error}]`, errorCb);
|
|
161
189
|
return false;
|
|
162
190
|
}
|
|
163
191
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
1
2
|
import { Kafka, Consumer, IHeaders } from 'kafkajs'
|
|
2
3
|
import { IKafkaConsumer } from './../commonTypes'
|
|
3
4
|
|
|
@@ -25,51 +26,58 @@ export class KafkaConsumer implements IKafkaConsumer {
|
|
|
25
26
|
return this.#id;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
#RaiseError = (msg: string, errorCb: (error: any) => void) => {
|
|
30
|
+
console.error(chalk.red(msg));
|
|
31
|
+
errorCb(msg);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async Connect(errorCb: (error: any) => void): Promise<void> {
|
|
29
35
|
if (!this.#connected) {
|
|
30
36
|
try {
|
|
31
37
|
await this.#consumer.connect()
|
|
32
38
|
this.#connected = true;
|
|
33
39
|
} catch (error) {
|
|
34
|
-
|
|
40
|
+
this.#RaiseError(`${process.pid}:KafkaConsumer:Connect(): Error: [${error}]`, errorCb);
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
async Disconnect(): Promise<void> {
|
|
45
|
+
async Disconnect(errorCb: (error: any) => void): Promise<void> {
|
|
40
46
|
if (this.#connected) {
|
|
41
47
|
try {
|
|
42
48
|
await this.#consumer.disconnect()
|
|
43
49
|
this.#connected = false;
|
|
44
50
|
} catch (error) {
|
|
45
|
-
|
|
51
|
+
this.#RaiseError(`${process.pid}:KafkaConsumer:Disconnect(): Error: [${error}]`, errorCb);
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
Subscribe = async(topics: string[], fromBeginning: boolean): Promise<void> => {
|
|
56
|
+
Subscribe = async(topics: string[], fromBeginning: boolean, errorCb: (error: any) => void): Promise<void> => {
|
|
51
57
|
if (this.#connected) {
|
|
52
58
|
try {
|
|
53
59
|
await this.#consumer.subscribe({ topics, fromBeginning })
|
|
54
60
|
} catch (error) {
|
|
55
|
-
|
|
61
|
+
this.#RaiseError(`${process.pid}:KafkaConsumer:Subscribe(): Error: [${error}]`, errorCb);
|
|
56
62
|
}
|
|
57
63
|
} else {
|
|
58
|
-
|
|
64
|
+
await this.Connect((error) => {
|
|
65
|
+
this.#RaiseError(`${process.pid}:KafkaProducer:Subscribe(): Could not consumer.connect, Error: [${error}]`, errorCb);
|
|
66
|
+
});
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
Stop = async(): Promise<void> => {
|
|
70
|
+
Stop = async(errorCb: (error: any) => void): Promise<void> => {
|
|
63
71
|
if (this.#connected) {
|
|
64
72
|
try {
|
|
65
73
|
await this.#consumer.stop();
|
|
66
74
|
} catch (error) {
|
|
67
|
-
|
|
75
|
+
this.#RaiseError(`${process.pid}:KafkaConsumer:Stop(): Error: [${error}]`, errorCb);
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
StartConsumingMessages = async (cb: (topic: string, key: string, partition: number, value: string, headers: IHeaders | undefined) => void): Promise<void> => {
|
|
80
|
+
StartConsumingMessages = async (cb: (topic: string, key: string, partition: number, value: string, headers: IHeaders | undefined) => void, errorCb: (error: any) => void): Promise<void> => {
|
|
73
81
|
if (this.#connected) {
|
|
74
82
|
await this.#consumer.run({
|
|
75
83
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -89,12 +97,14 @@ export class KafkaConsumer implements IKafkaConsumer {
|
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
} catch (error) {
|
|
92
|
-
|
|
100
|
+
this.#RaiseError(`${process.pid}:KafkaConsumer:StartConsumingMessages(): Error: [${error}]`, errorCb);
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
})
|
|
96
104
|
} else {
|
|
97
|
-
|
|
105
|
+
await this.Connect((error) => {
|
|
106
|
+
this.#RaiseError(`${process.pid}:KafkaProducer:StartConsumingMessages(): Could not consumer.connect, Error: [${error}]`, errorCb);
|
|
107
|
+
});
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
110
|
}
|