@nsshunt/stsappframework 3.1.174 → 3.1.175
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/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
- package/src/index.ts +0 -1
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/dist/kafka/IMKafkaManager.js +0 -226
- package/dist/kafka/IMKafkaManager.js.map +0 -1
- package/src/kafka/IMKafkaManager.ts +0 -242
- package/types/kafka/IMKafkaManager.d.ts +0 -15
- package/types/kafka/IMKafkaManager.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -28,7 +28,6 @@ __exportStar(require("./stslatencyroute"), exports);
|
|
|
28
28
|
__exportStar(require("./kafka/kafkamanager"), exports);
|
|
29
29
|
__exportStar(require("./kafka/kafkaproducer"), exports);
|
|
30
30
|
__exportStar(require("./kafka/kafkaconsumer"), exports);
|
|
31
|
-
__exportStar(require("./kafka/IMKafkaManager"), exports);
|
|
32
31
|
__exportStar(require("./influxdb/influxDBManager"), exports);
|
|
33
32
|
__exportStar(require("./influxdb/influxDBManagerBase"), exports);
|
|
34
33
|
__exportStar(require("./influxdb/influxDBManagerService"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,6CAA0B;AAC1B,kDAA+B;AAC/B,kDAA+B;AAC/B,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,yDAAsC;AACtC,yDAAsC;AACtC,oDAAiC;AACjC,uDAAoC;AACpC,wDAAqC;AACrC,wDAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,6CAA0B;AAC1B,kDAA+B;AAC/B,kDAA+B;AAC/B,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,yDAAsC;AACtC,yDAAsC;AACtC,oDAAiC;AACjC,uDAAoC;AACpC,wDAAqC;AACrC,wDAAqC;AACrC,6DAA0C;AAC1C,iEAA8C;AAC9C,oEAAiD;AACjD,kEAA+C;AAC/C,mEAAgD;AAChD,8EAA2D;AAC3D,wDAAqC;AACrC,8DAA2C;AAC3C,+DAA4C;AAC5C,8DAA2C;AAC3C,sDAAmC;AACnC,wDAAqC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsappframework",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.175",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/nsshunt/stsappframework#readme",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/preset-env": "^7.25.
|
|
28
|
+
"@babel/preset-env": "^7.25.4",
|
|
29
29
|
"@babel/preset-typescript": "^7.24.7",
|
|
30
30
|
"@eslint/eslintrc": "^3.1.0",
|
|
31
|
-
"@eslint/js": "^9.
|
|
31
|
+
"@eslint/js": "^9.9.1",
|
|
32
32
|
"@tsconfig/node20": "^20.1.4",
|
|
33
33
|
"@types/cookie-parser": "^1.4.7",
|
|
34
34
|
"@types/debug": "^4.1.12",
|
|
@@ -37,31 +37,31 @@
|
|
|
37
37
|
"@types/jest": "^29.5.12",
|
|
38
38
|
"@types/jsonwebtoken": "^9.0.6",
|
|
39
39
|
"@types/uuid": "^10.0.0",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
41
|
-
"@typescript-eslint/parser": "^8.
|
|
42
|
-
"eslint": "^9.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
42
|
+
"eslint": "^9.9.1",
|
|
43
43
|
"globals": "^15.9.0",
|
|
44
44
|
"jest": "^29.7.0",
|
|
45
|
-
"testcontainers": "^10.
|
|
45
|
+
"testcontainers": "^10.13.0",
|
|
46
46
|
"typescript": "^5.5.4",
|
|
47
|
-
"vite": "^5.
|
|
47
|
+
"vite": "^5.4.2",
|
|
48
48
|
"vitest": "^2.0.5"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@grpc/grpc-js": "^1.11.1",
|
|
52
52
|
"@grpc/proto-loader": "^0.7.13",
|
|
53
|
-
"@influxdata/influxdb-client": "^1.
|
|
54
|
-
"@influxdata/influxdb-client-apis": "^1.
|
|
55
|
-
"@nsshunt/stsconfig": "^1.25.
|
|
56
|
-
"@nsshunt/stsdatamanagement": "^1.18.
|
|
57
|
-
"@nsshunt/stsobservability": "^1.0.
|
|
58
|
-
"@nsshunt/stsutils": "^1.16.
|
|
53
|
+
"@influxdata/influxdb-client": "^1.35.0",
|
|
54
|
+
"@influxdata/influxdb-client-apis": "^1.35.0",
|
|
55
|
+
"@nsshunt/stsconfig": "^1.25.139",
|
|
56
|
+
"@nsshunt/stsdatamanagement": "^1.18.68",
|
|
57
|
+
"@nsshunt/stsobservability": "^1.0.42",
|
|
58
|
+
"@nsshunt/stsutils": "^1.16.68",
|
|
59
59
|
"@socket.io/cluster-adapter": "^0.2.2",
|
|
60
60
|
"@socket.io/redis-streams-adapter": "^0.2.2",
|
|
61
61
|
"@types/on-headers": "^1.0.3",
|
|
62
62
|
"@types/pidusage": "^2.0.5",
|
|
63
63
|
"@types/tough-cookie": "^4.0.5",
|
|
64
|
-
"axios": "^1.7.
|
|
64
|
+
"axios": "^1.7.7",
|
|
65
65
|
"chalk": "^4.1.2",
|
|
66
66
|
"cookie-parser": "^1.4.6",
|
|
67
67
|
"cors": "^2.8.5",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"detect-node": "^2.1.0",
|
|
70
70
|
"express": "^4.19.1",
|
|
71
71
|
"http-status-codes": "^2.3.0",
|
|
72
|
-
"jayson": "^4.1.
|
|
72
|
+
"jayson": "^4.1.2",
|
|
73
73
|
"jsonwebtoken": "^9.0.2",
|
|
74
74
|
"jwks-rsa": "^3.1.0",
|
|
75
75
|
"jwt-decode": "^4.0.0",
|
|
@@ -81,10 +81,10 @@
|
|
|
81
81
|
"socket.io": "^4.7.5",
|
|
82
82
|
"socket.io-client": "^4.7.5",
|
|
83
83
|
"supports-color": "^9.4.0",
|
|
84
|
-
"systeminformation": "^5.23.
|
|
84
|
+
"systeminformation": "^5.23.5",
|
|
85
85
|
"tiny-emitter": "^2.1.0",
|
|
86
86
|
"tough-cookie": "^4.1.4",
|
|
87
87
|
"uuid": "^10.0.0",
|
|
88
|
-
"winston": "^3.
|
|
88
|
+
"winston": "^3.14.2"
|
|
89
89
|
}
|
|
90
90
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ export * from './stslatencyroute'
|
|
|
12
12
|
export * from './kafka/kafkamanager'
|
|
13
13
|
export * from './kafka/kafkaproducer'
|
|
14
14
|
export * from './kafka/kafkaconsumer'
|
|
15
|
-
export * from './kafka/IMKafkaManager'
|
|
16
15
|
export * from './influxdb/influxDBManager'
|
|
17
16
|
export * from './influxdb/influxDBManagerBase'
|
|
18
17
|
export * from './influxdb/influxDBManagerService'
|
package/types/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export * from './stslatencyroute';
|
|
|
12
12
|
export * from './kafka/kafkamanager';
|
|
13
13
|
export * from './kafka/kafkaproducer';
|
|
14
14
|
export * from './kafka/kafkaconsumer';
|
|
15
|
-
export * from './kafka/IMKafkaManager';
|
|
16
15
|
export * from './influxdb/influxDBManager';
|
|
17
16
|
export * from './influxdb/influxDBManagerBase';
|
|
18
17
|
export * from './influxdb/influxDBManagerService';
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA"}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IMKafkaManager = void 0;
|
|
7
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
8
|
-
const stsobservability_1 = require("@nsshunt/stsobservability");
|
|
9
|
-
const kafkamanager_1 = require("./kafkamanager");
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
-
const stsconfig_1 = require("@nsshunt/stsconfig");
|
|
13
|
-
// Manage the publication of InstrumentPayload to Kafka
|
|
14
|
-
class IMKafkaManager {
|
|
15
|
-
#options;
|
|
16
|
-
#shuttingDown = false;
|
|
17
|
-
#producer = null;
|
|
18
|
-
#km;
|
|
19
|
-
#topics = {};
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this.#options = options;
|
|
22
|
-
const kmc = {
|
|
23
|
-
clientId: `${stsconfig_1.goptions.kafka_clientId}_${(0, uuid_1.v4)()}`,
|
|
24
|
-
brokers: stsconfig_1.goptions.kafka_brokers.split(','),
|
|
25
|
-
keepAlive: stsconfig_1.goptions.kafka_keep_alive,
|
|
26
|
-
adminTimeout: stsconfig_1.goptions.kafka_admin_timeout,
|
|
27
|
-
connectionTimeout: stsconfig_1.goptions.kafka_connection_timeout,
|
|
28
|
-
logLevel: stsconfig_1.goptions.kafka_log_level,
|
|
29
|
-
useSSL: stsconfig_1.goptions.kafka_use_ssl,
|
|
30
|
-
requestTimeout: stsconfig_1.goptions.kafka_request_timeout,
|
|
31
|
-
logger: options.logger
|
|
32
|
-
};
|
|
33
|
-
if (stsconfig_1.goptions.kafka_use_ssl) {
|
|
34
|
-
kmc.ssl = {
|
|
35
|
-
rejectUnauthorized: stsconfig_1.goptions.kafka_ssl_rejectUnauthorized,
|
|
36
|
-
cafile: stsconfig_1.goptions.kafka_ssl_cafile,
|
|
37
|
-
certfileFile: stsconfig_1.goptions.kafka_ssl_certfile,
|
|
38
|
-
keyfile: stsconfig_1.goptions.kafka_ssl_keyfile
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
this.#km = new kafkamanager_1.KafkaManager(kmc);
|
|
42
|
-
}
|
|
43
|
-
#LogErrorMessage(message) {
|
|
44
|
-
this.#options.logger.error(message);
|
|
45
|
-
}
|
|
46
|
-
#LogDebugMessage(message) {
|
|
47
|
-
this.#options.logger.debug(message);
|
|
48
|
-
}
|
|
49
|
-
#RaiseError = (msg, errorCb) => {
|
|
50
|
-
this.#LogErrorMessage(chalk_1.default.red(msg));
|
|
51
|
-
errorCb(msg);
|
|
52
|
-
};
|
|
53
|
-
get km() {
|
|
54
|
-
return this.#km;
|
|
55
|
-
}
|
|
56
|
-
Start = async (errorCb) => {
|
|
57
|
-
this.#producer = this.#km.CreateProducer();
|
|
58
|
-
await this.#producer.Connect((error) => {
|
|
59
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Start(): Error: [${error}]`, errorCb);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
Terminate = async (errorCb) => {
|
|
63
|
-
try {
|
|
64
|
-
if (this.#shuttingDown) {
|
|
65
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`${process.pid}:IMKafkaManager:Terminate: Terminate already called. Ignoring.`));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
this.#shuttingDown = true;
|
|
69
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`${process.pid}:ProducerDisconnect`));
|
|
70
|
-
if (this.#producer) {
|
|
71
|
-
await this.#producer.Disconnect((error) => {
|
|
72
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error in producer.Disconnect: [${error}]`, errorCb);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error: [${error}]`, errorCb);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
async #OutputLogsToKafkaTopic(topicRaw, logMessages, errorCb) {
|
|
82
|
-
const topic = topicRaw.toLowerCase();
|
|
83
|
-
try {
|
|
84
|
-
if (!this.#topics[topic]) {
|
|
85
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Starting`));
|
|
86
|
-
this.#topics[topic] = true;
|
|
87
|
-
let createTopicError = false;
|
|
88
|
-
const result = await this.#km.CreateTopic(topic, 1, (error) => {
|
|
89
|
-
createTopicError = true;
|
|
90
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Error in km.CreateTopic: [${error}]`, errorCb);
|
|
91
|
-
});
|
|
92
|
-
if (!createTopicError) {
|
|
93
|
-
if (result) {
|
|
94
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed`));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
this.#LogDebugMessage(chalk_1.default.cyan(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed - topic already exists`));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error: [${error}]`, errorCb);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const messages = [];
|
|
108
|
-
logMessages.forEach((m) => {
|
|
109
|
-
messages.push({ key: topic, value: m });
|
|
110
|
-
});
|
|
111
|
-
// Don't wait for these to return ...
|
|
112
|
-
if (this.#producer) {
|
|
113
|
-
this.#producer.SendMessages(topic, messages, (error) => {
|
|
114
|
-
this.#LogErrorMessage(chalk_1.default.red(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages: [${error}]`));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages (2): [${error}]`, errorCb);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async OutputLogs(instrumentPayload, errorCb) {
|
|
123
|
-
try {
|
|
124
|
-
if (this.#shuttingDown) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
let topic = '';
|
|
128
|
-
if (instrumentPayload.instruments[stsobservability_1.Gauge.LOGGER]) {
|
|
129
|
-
const loggerMessages = [...instrumentPayload.instruments[stsobservability_1.Gauge.LOGGER].val];
|
|
130
|
-
if (loggerMessages.length > 0) {
|
|
131
|
-
if (instrumentPayload.context.agentName) {
|
|
132
|
-
// Processing agent payload
|
|
133
|
-
const { agentName, threadId, asyncRunnerId } = instrumentPayload.context;
|
|
134
|
-
topic = '';
|
|
135
|
-
if (agentName && threadId && asyncRunnerId !== undefined) {
|
|
136
|
-
// Output logs for a specific asyncRunnerId
|
|
137
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${agentName}_${threadId}_${asyncRunnerId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
138
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
139
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId && asyncRunnerId): [${error}]`, errorCb);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (agentName && threadId) {
|
|
143
|
-
// Output logs for a specific thread (worker) within an agent
|
|
144
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${agentName}_${threadId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
145
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
146
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId): [${error}]`, errorCb);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (agentName) {
|
|
150
|
-
// Output logs for a specific thread (worker) within an agent
|
|
151
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${agentName}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
152
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
153
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName): [${error}]`, errorCb);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else if (instrumentPayload.context.lambdaFunctionName) {
|
|
158
|
-
/*
|
|
159
|
-
export interface ILambdaProcessContext extends IProcessContextBase {
|
|
160
|
-
technology: string // e.g. aws, azure, node, postgresql
|
|
161
|
-
subTechnology: string // (use {technology_subTechnology}) aws_s3, aws_sqs, azure_blob, node_workerthreads, postgresql_crud
|
|
162
|
-
lambdaFunctionName: string
|
|
163
|
-
lambdaInstance: string // uuid of this lambda function running
|
|
164
|
-
hostName: string // The host where this lambda class is running
|
|
165
|
-
processId: string // The process id (pid) on the host where this lambda class is running
|
|
166
|
-
parentProcessId: string // The parent process id (ppid) on the host where this lambda class is running
|
|
167
|
-
useCase: string // The use case that this lambda function supports
|
|
168
|
-
pattern: string // The pattern that this lambda function is part of
|
|
169
|
-
metaData?: Record<string, string> // (optional) Any additional meta-data associated with this lambda function that is not defined within this context
|
|
170
|
-
}
|
|
171
|
-
*/
|
|
172
|
-
// Processing lambda payload
|
|
173
|
-
const { technology, subTechnology, lambdaInstance } = instrumentPayload.context;
|
|
174
|
-
topic = '';
|
|
175
|
-
if (technology && subTechnology && lambdaInstance !== undefined) {
|
|
176
|
-
// Output logs for a specific lambdaInstance
|
|
177
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${technology}_${subTechnology}_${lambdaInstance}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
178
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
179
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology && subTechnology && lambdaInstance): [${error}]`, errorCb);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if (technology && subTechnology) {
|
|
183
|
-
// Output logs for a specific subTechnology within an technology
|
|
184
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${technology}_${subTechnology}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
185
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
186
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology && subTechnology): [${error}]`, errorCb);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (technology) {
|
|
190
|
-
// Output logs for a specific technology
|
|
191
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${technology}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
192
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
193
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology): [${error}]`, errorCb);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// Processing service payload
|
|
199
|
-
const { serviceInstanceId, serviceInstanceProcessId, pid, ppid } = instrumentPayload.context;
|
|
200
|
-
if (serviceInstanceId && serviceInstanceProcessId && pid && ppid) {
|
|
201
|
-
// Output to the specific thread within an instance
|
|
202
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${serviceInstanceId}_${serviceInstanceProcessId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
203
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
204
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (serviceInstanceId && serviceInstanceProcessId && pid && ppid): [${error}]`, errorCb);
|
|
205
|
-
});
|
|
206
|
-
if (pid === ppid) {
|
|
207
|
-
// Output only to the main thread on the service, i.e. this is for O/A service logging
|
|
208
|
-
topic = `${stsobservability_1.KAFKA_PREFIX}_${serviceInstanceId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
209
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
210
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (pid === ppid): [${error}]`, errorCb);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Error: [${error}]`, errorCb);
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.IMKafkaManager = IMKafkaManager;
|
|
226
|
-
//# sourceMappingURL=IMKafkaManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IMKafkaManager.js","sourceRoot":"","sources":["../../src/kafka/IMKafkaManager.ts"],"names":[],"mappings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AI,iBAAiB,IAAI,wBAAwB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;4BAClH,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,KAAK,EAAE,EAAE;gCAC1D,IAAI,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,GAAG,+CAA+C,KAAK,2GAA2G,KAAK,GAAG,EAAE,OAAO,CAAC,CAAC;4BACrN,CAAC,CAAC,CAAC;4BAEH,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gCACf,sFAAsF;gCACtF,KAAK,GAAG,GAAG,+BAAY,IAAI,iBAAiB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gCACtF,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,KAAK,EAAE,EAAE;oCAC1D,IAAI,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,GAAG,+CAA+C,KAAK,2DAA2D,KAAK,GAAG,EAAE,OAAO,CAAC,CAAC;gCACrK,CAAC,CAAC,CAAC;4BACP,CAAC;wBACL,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,IAAI,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,GAAG,yCAAyC,KAAK,GAAG,EAAE,OAAO,CAAC,CAAC;YAC3F,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ;AA/ND,wCA+NC"}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import { Gauge, KAFKA_PREFIX, IInstrumentPayload } from '@nsshunt/stsobservability'
|
|
3
|
-
|
|
4
|
-
import { KafkaManager, IKafkaManagerConfig } from './kafkamanager'
|
|
5
|
-
import { KafkaProducer } from './kafkaproducer'
|
|
6
|
-
|
|
7
|
-
import { ISTSLogger, JSONObject } from '@nsshunt/stsutils'
|
|
8
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
-
|
|
10
|
-
import chalk from 'chalk';
|
|
11
|
-
|
|
12
|
-
import { goptions } from '@nsshunt/stsconfig'
|
|
13
|
-
|
|
14
|
-
export interface IMKafkaManagerOptions {
|
|
15
|
-
logger: ISTSLogger
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Manage the publication of InstrumentPayload to Kafka
|
|
19
|
-
export class IMKafkaManager {
|
|
20
|
-
#options: IMKafkaManagerOptions;
|
|
21
|
-
#shuttingDown: boolean = false;
|
|
22
|
-
#producer: KafkaProducer | null = null;
|
|
23
|
-
|
|
24
|
-
#km: KafkaManager;
|
|
25
|
-
#topics: JSONObject = { }
|
|
26
|
-
|
|
27
|
-
constructor(options: IMKafkaManagerOptions)
|
|
28
|
-
{
|
|
29
|
-
this.#options = options;
|
|
30
|
-
|
|
31
|
-
const kmc: IKafkaManagerConfig = {
|
|
32
|
-
clientId: `${goptions.kafka_clientId}_${uuidv4()}`,
|
|
33
|
-
brokers: goptions.kafka_brokers.split(','),
|
|
34
|
-
keepAlive: goptions.kafka_keep_alive,
|
|
35
|
-
adminTimeout: goptions.kafka_admin_timeout,
|
|
36
|
-
connectionTimeout: goptions.kafka_connection_timeout,
|
|
37
|
-
logLevel: goptions.kafka_log_level,
|
|
38
|
-
useSSL: goptions.kafka_use_ssl,
|
|
39
|
-
requestTimeout: goptions.kafka_request_timeout,
|
|
40
|
-
logger: options.logger
|
|
41
|
-
}
|
|
42
|
-
if (goptions.kafka_use_ssl) {
|
|
43
|
-
kmc.ssl = {
|
|
44
|
-
rejectUnauthorized: goptions.kafka_ssl_rejectUnauthorized,
|
|
45
|
-
cafile: goptions.kafka_ssl_cafile,
|
|
46
|
-
certfileFile: goptions.kafka_ssl_certfile,
|
|
47
|
-
keyfile: goptions.kafka_ssl_keyfile
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.#km = new KafkaManager(kmc);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
#LogErrorMessage(message: any) {
|
|
55
|
-
this.#options.logger.error(message);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#LogDebugMessage(message: any) {
|
|
59
|
-
this.#options.logger.debug(message);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#RaiseError = (msg: string, errorCb: (error: any) => void) => {
|
|
63
|
-
this.#LogErrorMessage(chalk.red(msg));
|
|
64
|
-
errorCb(msg);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get km(): KafkaManager {
|
|
68
|
-
return this.#km;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
Start = async (errorCb: (error: any) => void): Promise<void> => {
|
|
72
|
-
this.#producer = this.#km.CreateProducer();
|
|
73
|
-
await this.#producer.Connect((error) => {
|
|
74
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Start(): Error: [${error}]`, errorCb);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
Terminate = async (errorCb: (error: any) => void): Promise<void> => {
|
|
79
|
-
try {
|
|
80
|
-
if (this.#shuttingDown) {
|
|
81
|
-
this.#LogDebugMessage(chalk.yellow(`${process.pid}:IMKafkaManager:Terminate: Terminate already called. Ignoring.`));
|
|
82
|
-
} else {
|
|
83
|
-
this.#shuttingDown = true;
|
|
84
|
-
this.#LogDebugMessage(chalk.yellow(`${process.pid}:ProducerDisconnect`));
|
|
85
|
-
if (this.#producer) {
|
|
86
|
-
await this.#producer.Disconnect((error) => {
|
|
87
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error in producer.Disconnect: [${error}]`, errorCb);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:Terminate(): Error: [${error}]`, errorCb);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async #OutputLogsToKafkaTopic(topicRaw: string, logMessages: string[], errorCb: (error: any) => void) {
|
|
97
|
-
const topic = topicRaw.toLowerCase();
|
|
98
|
-
try {
|
|
99
|
-
if (!this.#topics[topic]) {
|
|
100
|
-
this.#LogDebugMessage(chalk.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Starting`));
|
|
101
|
-
this.#topics[topic] = true;
|
|
102
|
-
|
|
103
|
-
let createTopicError = false;
|
|
104
|
-
const result = await this.#km.CreateTopic(topic, 1, (error) => {
|
|
105
|
-
createTopicError = true;
|
|
106
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Error in km.CreateTopic: [${error}]`, errorCb);
|
|
107
|
-
});
|
|
108
|
-
if (!createTopicError) {
|
|
109
|
-
if (result) {
|
|
110
|
-
this.#LogDebugMessage(chalk.yellow(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed`));
|
|
111
|
-
} else {
|
|
112
|
-
this.#LogDebugMessage(chalk.cyan(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Setting up kafka topic: [${topic}] Completed - topic already exists`));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error: [${error}]`, errorCb);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
const messages: JSONObject[] = [ ];
|
|
123
|
-
logMessages.forEach((m) => {
|
|
124
|
-
messages.push({key: topic, value: m})
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Don't wait for these to return ...
|
|
128
|
-
if (this.#producer) {
|
|
129
|
-
this.#producer.SendMessages(topic, messages as any, (error) => {
|
|
130
|
-
this.#LogErrorMessage(chalk.red(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages: [${error}]`));
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
} catch (error) {
|
|
134
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogsToKafkaTopic(): Kafka topic: [${topic}], Error during producer.SendMessages (2): [${error}]`, errorCb);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async OutputLogs(instrumentPayload: IInstrumentPayload, errorCb: (error: any) => void): Promise<boolean> {
|
|
139
|
-
try {
|
|
140
|
-
if (this.#shuttingDown) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let topic: string = '';
|
|
145
|
-
if (instrumentPayload.instruments[Gauge.LOGGER]) {
|
|
146
|
-
const loggerMessages = [ ...instrumentPayload.instruments[Gauge.LOGGER].val as string[] ];
|
|
147
|
-
if (loggerMessages.length > 0) {
|
|
148
|
-
if (instrumentPayload.context.agentName) {
|
|
149
|
-
// Processing agent payload
|
|
150
|
-
const { agentName, threadId, asyncRunnerId } = instrumentPayload.context;
|
|
151
|
-
|
|
152
|
-
topic = '';
|
|
153
|
-
if (agentName && threadId && asyncRunnerId !== undefined) {
|
|
154
|
-
// Output logs for a specific asyncRunnerId
|
|
155
|
-
topic = `${KAFKA_PREFIX}_${agentName}_${threadId}_${asyncRunnerId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
156
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
157
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId && asyncRunnerId): [${error}]`, errorCb);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (agentName && threadId) {
|
|
161
|
-
// Output logs for a specific thread (worker) within an agent
|
|
162
|
-
topic = `${KAFKA_PREFIX}_${agentName}_${threadId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
163
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
164
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName && threadId): [${error}]`, errorCb);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
if (agentName) {
|
|
168
|
-
// Output logs for a specific thread (worker) within an agent
|
|
169
|
-
topic = `${KAFKA_PREFIX}_${agentName}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
170
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
171
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (agentName): [${error}]`, errorCb);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
} else if (instrumentPayload.context.lambdaFunctionName) {
|
|
175
|
-
/*
|
|
176
|
-
export interface ILambdaProcessContext extends IProcessContextBase {
|
|
177
|
-
technology: string // e.g. aws, azure, node, postgresql
|
|
178
|
-
subTechnology: string // (use {technology_subTechnology}) aws_s3, aws_sqs, azure_blob, node_workerthreads, postgresql_crud
|
|
179
|
-
lambdaFunctionName: string
|
|
180
|
-
lambdaInstance: string // uuid of this lambda function running
|
|
181
|
-
hostName: string // The host where this lambda class is running
|
|
182
|
-
processId: string // The process id (pid) on the host where this lambda class is running
|
|
183
|
-
parentProcessId: string // The parent process id (ppid) on the host where this lambda class is running
|
|
184
|
-
useCase: string // The use case that this lambda function supports
|
|
185
|
-
pattern: string // The pattern that this lambda function is part of
|
|
186
|
-
metaData?: Record<string, string> // (optional) Any additional meta-data associated with this lambda function that is not defined within this context
|
|
187
|
-
}
|
|
188
|
-
*/
|
|
189
|
-
|
|
190
|
-
// Processing lambda payload
|
|
191
|
-
const { technology, subTechnology, lambdaInstance } = instrumentPayload.context;
|
|
192
|
-
|
|
193
|
-
topic = '';
|
|
194
|
-
if (technology && subTechnology && lambdaInstance !== undefined) {
|
|
195
|
-
// Output logs for a specific lambdaInstance
|
|
196
|
-
topic = `${KAFKA_PREFIX}_${technology}_${subTechnology}_${lambdaInstance}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
197
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
198
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology && subTechnology && lambdaInstance): [${error}]`, errorCb);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
if (technology && subTechnology) {
|
|
202
|
-
// Output logs for a specific subTechnology within an technology
|
|
203
|
-
topic = `${KAFKA_PREFIX}_${technology}_${subTechnology}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
204
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
205
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology && subTechnology): [${error}]`, errorCb);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
if (technology) {
|
|
209
|
-
// Output logs for a specific technology
|
|
210
|
-
topic = `${KAFKA_PREFIX}_${technology}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
211
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
212
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (technology): [${error}]`, errorCb);
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
// Processing service payload
|
|
217
|
-
const { serviceInstanceId, serviceInstanceProcessId, pid, ppid } = instrumentPayload.context;
|
|
218
|
-
if (serviceInstanceId && serviceInstanceProcessId && pid && ppid) {
|
|
219
|
-
// Output to the specific thread within an instance
|
|
220
|
-
topic = `${KAFKA_PREFIX}_${serviceInstanceId}_${serviceInstanceProcessId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
221
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
222
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (serviceInstanceId && serviceInstanceProcessId && pid && ppid): [${error}]`, errorCb);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
if (pid === ppid) {
|
|
226
|
-
// Output only to the main thread on the service, i.e. this is for O/A service logging
|
|
227
|
-
topic = `${KAFKA_PREFIX}_${serviceInstanceId}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
228
|
-
this.#OutputLogsToKafkaTopic(topic, loggerMessages, (error) => {
|
|
229
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Kafka topic: [${topic}], Error during OutputLogsToKafkaTopic (pid === ppid): [${error}]`, errorCb);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return true;
|
|
237
|
-
} catch (error: any) {
|
|
238
|
-
this.#RaiseError(`${process.pid}:IMKafkaManager:OutputLogs(): Error: [${error}]`, errorCb);
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IInstrumentPayload } from '@nsshunt/stsobservability';
|
|
2
|
-
import { KafkaManager } from './kafkamanager';
|
|
3
|
-
import { ISTSLogger } from '@nsshunt/stsutils';
|
|
4
|
-
export interface IMKafkaManagerOptions {
|
|
5
|
-
logger: ISTSLogger;
|
|
6
|
-
}
|
|
7
|
-
export declare class IMKafkaManager {
|
|
8
|
-
#private;
|
|
9
|
-
constructor(options: IMKafkaManagerOptions);
|
|
10
|
-
get km(): KafkaManager;
|
|
11
|
-
Start: (errorCb: (error: any) => void) => Promise<void>;
|
|
12
|
-
Terminate: (errorCb: (error: any) => void) => Promise<void>;
|
|
13
|
-
OutputLogs(instrumentPayload: IInstrumentPayload, errorCb: (error: any) => void): Promise<boolean>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=IMKafkaManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IMKafkaManager.d.ts","sourceRoot":"","sources":["../../src/kafka/IMKafkaManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEnF,OAAO,EAAE,YAAY,EAAuB,MAAM,gBAAgB,CAAA;AAGlE,OAAO,EAAE,UAAU,EAAc,MAAM,mBAAmB,CAAA;AAO1D,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,UAAU,CAAA;CACrB;AAGD,qBAAa,cAAc;;gBAQX,OAAO,EAAE,qBAAqB;IAwC1C,IAAI,EAAE,IAAI,YAAY,CAErB;IAED,KAAK,YAAmB,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,KAAG,OAAO,CAAC,IAAI,CAAC,CAK3D;IAED,SAAS,YAAmB,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,KAAG,OAAO,CAAC,IAAI,CAAC,CAgB/D;IA4CK,UAAU,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;CAwG3G"}
|