@itentialopensource/adapter-kafkav2 0.16.0 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/adapter.js +247 -199
- package/package.json +1 -1
- package/refs?service=git-upload-pack +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
|
|
2
|
+
## 0.16.2 [08-29-2023]
|
|
3
|
+
|
|
4
|
+
* Big fixes logLevel and adapter restart
|
|
5
|
+
|
|
6
|
+
See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!15
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 0.16.1 [08-24-2023]
|
|
11
|
+
|
|
12
|
+
* Handle empty topics file
|
|
13
|
+
|
|
14
|
+
See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!13
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
2
18
|
## 0.16.0 [08-23-2023]
|
|
3
19
|
|
|
4
20
|
* Add logic to clean topics.json from service config
|
package/adapter.js
CHANGED
|
@@ -22,6 +22,8 @@ const util = require('util');
|
|
|
22
22
|
const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
|
|
23
23
|
const request = require('request');
|
|
24
24
|
|
|
25
|
+
let needRestart = false;
|
|
26
|
+
|
|
25
27
|
function consoleLoggerProvider(name) {
|
|
26
28
|
return {
|
|
27
29
|
debug: log.debug,
|
|
@@ -33,6 +35,14 @@ function consoleLoggerProvider(name) {
|
|
|
33
35
|
|
|
34
36
|
const { Kafka, logLevel } = require('kafkajs');
|
|
35
37
|
|
|
38
|
+
const LogLevelEnum = {
|
|
39
|
+
NOTHING: logLevel.NOTHING,
|
|
40
|
+
ERROR: logLevel.ERROR,
|
|
41
|
+
WARN: logLevel.WARN,
|
|
42
|
+
INFO: logLevel.INFO,
|
|
43
|
+
DEBUG: logLevel.DEBUG
|
|
44
|
+
};
|
|
45
|
+
|
|
36
46
|
const pjson = require(path.resolve(__dirname, 'pronghorn.json'));
|
|
37
47
|
|
|
38
48
|
let myid = null;
|
|
@@ -42,6 +52,14 @@ let firstDone = false;
|
|
|
42
52
|
const mytopics = Object.keys(pjson.topics);
|
|
43
53
|
const pronghornFile = path.join(__dirname, '/pronghorn.json');
|
|
44
54
|
|
|
55
|
+
// Function to convert a log level string to the corresponding enum value
|
|
56
|
+
function convertLogLevel(logLevelStr) {
|
|
57
|
+
// Remove 'logLevel.' prefix if it exists
|
|
58
|
+
const logLevelStrClean = logLevelStr.replace('logLevel.', '');
|
|
59
|
+
const logLevelEnum = LogLevelEnum[logLevelStrClean];
|
|
60
|
+
return logLevelEnum !== undefined ? logLevelEnum : logLevel.INFO; // Default to INFO if not found
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
async function fetchSchema(registryUrl, topic, version) {
|
|
46
64
|
return new Promise((resolve, reject) => {
|
|
47
65
|
log.debug(`${registryUrl}/subjects/${topic}/versions/${version}`);
|
|
@@ -181,13 +199,31 @@ class Kafkav2 extends AdapterBaseCl {
|
|
|
181
199
|
this.topicsEvents = [];
|
|
182
200
|
let topicsFile = path.join(__dirname, `/.topics-${this.id}.json`);
|
|
183
201
|
|
|
184
|
-
// if the file
|
|
202
|
+
// Check if the file exists
|
|
185
203
|
if (fs.existsSync(topicsFile)) {
|
|
186
|
-
|
|
204
|
+
const fileContent = fs.readFileSync(topicsFile, 'utf-8');
|
|
205
|
+
|
|
206
|
+
// Check if the file is empty
|
|
207
|
+
if (fileContent.trim() === '') {
|
|
208
|
+
// If it's empty, write an empty array to the file
|
|
209
|
+
fs.writeFileSync(topicsFile, '[]');
|
|
210
|
+
} else {
|
|
211
|
+
// Parse the existing content
|
|
212
|
+
this.topicsEvents = JSON.parse(fileContent);
|
|
213
|
+
}
|
|
187
214
|
} else if (fs.existsSync(path.join(__dirname, '/.topics.json'))) {
|
|
188
215
|
log.debug('Found old .topics.json file.');
|
|
189
216
|
topicsFile = path.join(__dirname, '/.topics.json');
|
|
190
|
-
|
|
217
|
+
const fileContent = fs.readFileSync(topicsFile, 'utf-8');
|
|
218
|
+
|
|
219
|
+
// Check if the file is empty
|
|
220
|
+
if (fileContent.trim() === '') {
|
|
221
|
+
// If it's empty, write an empty array to the file
|
|
222
|
+
fs.writeFileSync(topicsFile, '[]');
|
|
223
|
+
} else {
|
|
224
|
+
// Parse the existing content
|
|
225
|
+
this.topicsEvents = JSON.parse(fileContent);
|
|
226
|
+
}
|
|
191
227
|
}
|
|
192
228
|
|
|
193
229
|
// get the topics into the right format --- fix older .topics.json files so they have the right format
|
|
@@ -233,9 +269,7 @@ class Kafkav2 extends AdapterBaseCl {
|
|
|
233
269
|
}
|
|
234
270
|
|
|
235
271
|
// If we have a rabbit queue - need to add that to topics.json
|
|
236
|
-
// if there are topics in the properties
|
|
237
272
|
if (this.props && this.props.topics) {
|
|
238
|
-
let needRestart = false;
|
|
239
273
|
for (let t = 0; t < this.props.topics.length; t += 1) {
|
|
240
274
|
if (typeof this.props.topics[t] === 'string') {
|
|
241
275
|
const topName = this.props.topics[t];
|
|
@@ -467,229 +501,243 @@ class Kafkav2 extends AdapterBaseCl {
|
|
|
467
501
|
return;
|
|
468
502
|
}
|
|
469
503
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
combinedProps
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
504
|
+
if (!needRestart) {
|
|
505
|
+
try {
|
|
506
|
+
if (this.props.client.logLevel) {
|
|
507
|
+
const logLevelEnum = convertLogLevel(this.props.client.logLevel);
|
|
508
|
+
this.props.client.logLevel = logLevelEnum;
|
|
509
|
+
}
|
|
510
|
+
// Create a kafka client
|
|
511
|
+
const combinedProps = this.props.client || {};
|
|
512
|
+
if (this.props.client.ssl && this.props.client.ssl.ca) {
|
|
513
|
+
combinedProps.ssl.ca = [fs.readFileSync(this.props.client.ssl.ca, 'utf-8')];
|
|
514
|
+
}
|
|
515
|
+
if (this.props.client.ssl && this.props.client.ssl.cert) {
|
|
516
|
+
combinedProps.ssl.cert = fs.readFileSync(this.props.client.ssl.cert, 'utf-8');
|
|
517
|
+
}
|
|
518
|
+
if (this.props.client.ssl && this.props.client.ssl.key) {
|
|
519
|
+
combinedProps.ssl.key = fs.readFileSync(this.props.client.ssl.key, 'utf-8');
|
|
520
|
+
}
|
|
482
521
|
|
|
483
|
-
|
|
522
|
+
this.KafkaClient = new Kafka(combinedProps);
|
|
484
523
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
524
|
+
if (this.props.client && this.props.client.producersasl) {
|
|
525
|
+
combinedProps.sasl = this.props.client.producersasl;
|
|
526
|
+
this.KafkaProducerClient = new Kafka(combinedProps);
|
|
527
|
+
this.producer = this.KafkaProducerClient.producer(this.props.producer || {});
|
|
528
|
+
} else {
|
|
529
|
+
this.producer = this.KafkaClient.producer(this.props.producer || {});
|
|
530
|
+
}
|
|
492
531
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
532
|
+
if (this.props.client && this.props.client.consumersasl) {
|
|
533
|
+
combinedProps.sasl = this.props.client.consumersasl;
|
|
534
|
+
this.KafkaConsumerClient = new Kafka(combinedProps);
|
|
535
|
+
this.consumer = this.KafkaConsumerClient.consumer(this.props.consumer || {});
|
|
536
|
+
} else {
|
|
537
|
+
this.consumer = this.KafkaClient.consumer(this.props.consumer || {});
|
|
538
|
+
}
|
|
500
539
|
|
|
501
|
-
|
|
502
|
-
|
|
540
|
+
const isPassingFiltering = (topic, message, filters) => {
|
|
541
|
+
const topicConfig = this.topicsEvents.find((e) => e.topic === topic);
|
|
503
542
|
|
|
504
|
-
|
|
543
|
+
if (!topicConfig) return true;
|
|
505
544
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
545
|
+
if (!topicConfig.subInfo || !Array.isArray(topicConfig.subInfo)) return true;
|
|
546
|
+
if (filters.length === 0) return true;
|
|
547
|
+
const matched = filters.find((filter) => {
|
|
548
|
+
const re = new RegExp(filter);
|
|
549
|
+
if (message.value.toString().match(re)) {
|
|
550
|
+
log.debug('Matched filter: ', re);
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
return false;
|
|
554
|
+
});
|
|
555
|
+
return matched;
|
|
556
|
+
};
|
|
518
557
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
await this.consumer.connect();
|
|
531
|
-
await this.consumer.subscribe({ topics, fromBeginning: this.props.fromBeginning || false });
|
|
532
|
-
|
|
533
|
-
let isAppActive = null;
|
|
534
|
-
const topicPartitions = topics.map((topic) => ({ topic }));
|
|
535
|
-
|
|
536
|
-
// if any IAP apps are down, pause consumer before it consumes any messages
|
|
537
|
-
if (this.props && this.props.check_iap_apps) {
|
|
538
|
-
isAppActive = await super.checkIapAppsStatus();
|
|
539
|
-
if (!isAppActive) {
|
|
540
|
-
log.debug('Pause consumer since IAP apps are down');
|
|
541
|
-
// wait for the consumer to connect to Kafka before pausing it
|
|
542
|
-
this.consumer.on(this.consumer.events.CONNECT, async () => {
|
|
543
|
-
this.consumer.pause(topicPartitions);
|
|
544
|
-
});
|
|
558
|
+
const run = async () => {
|
|
559
|
+
this.emit('ONLINE', {
|
|
560
|
+
id: this.id
|
|
561
|
+
});
|
|
562
|
+
log.info('EMITTED ONLINE');
|
|
563
|
+
// Start consuming
|
|
564
|
+
// Iterate through all topics in topicsEvents
|
|
565
|
+
const topics = [];
|
|
566
|
+
for (let t = 0; t < this.topicsEvents.length; t += 1) {
|
|
567
|
+
topics.push(this.topicsEvents[t].topic);
|
|
545
568
|
}
|
|
546
|
-
|
|
569
|
+
await this.consumer.connect();
|
|
570
|
+
await this.consumer.subscribe({ topics, fromBeginning: this.props.fromBeginning || false });
|
|
547
571
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
572
|
+
let isAppActive = null;
|
|
573
|
+
const topicPartitions = topics.map((topic) => ({ topic }));
|
|
574
|
+
|
|
575
|
+
// if any IAP apps are down, pause consumer before it consumes any messages
|
|
576
|
+
if (this.props && this.props.check_iap_apps) {
|
|
552
577
|
isAppActive = await super.checkIapAppsStatus();
|
|
553
|
-
if (isAppActive) {
|
|
554
|
-
log.debug('
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
578
|
+
if (!isAppActive) {
|
|
579
|
+
log.debug('Pause consumer since IAP apps are down');
|
|
580
|
+
// wait for the consumer to connect to Kafka before pausing it
|
|
581
|
+
this.consumer.on(this.consumer.events.CONNECT, async () => {
|
|
582
|
+
this.consumer.pause(topicPartitions);
|
|
583
|
+
});
|
|
559
584
|
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
await this.consumer.run({
|
|
563
|
-
eachMessage: async ({ topic, partition, message }) => {
|
|
564
|
-
log.info(`PROCESSING NEW MESSAGE ON TOPIC: ${topic} PARTITION: ${partition} WITH OFFSET: ${message.offset}`);
|
|
565
|
-
const newMsg = message;
|
|
566
|
-
let avroUsed = false;
|
|
567
|
-
let desiredTopic = [];
|
|
568
|
-
let allowedPartition = false;
|
|
569
|
-
|
|
570
|
-
// if using avro
|
|
571
|
-
if (this.registry && avroUsed) {
|
|
572
|
-
// will give us an interval between 5001 and 60000 milliseconds (5 seconds to 1 minute)
|
|
573
|
-
const fastInt = Math.floor(Math.random() * 55000) + 5001;
|
|
585
|
+
}
|
|
574
586
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
587
|
+
// keep checking IAP apps status
|
|
588
|
+
if (this.props && this.props.check_iap_apps) {
|
|
589
|
+
const intTime = this.props.iap_apps_check_interval || 30000;
|
|
590
|
+
setInterval(async () => {
|
|
591
|
+
isAppActive = await super.checkIapAppsStatus();
|
|
592
|
+
if (isAppActive) {
|
|
593
|
+
log.debug('Resume consumer since IAP apps are active');
|
|
594
|
+
// wait for the consumer to connect to Kafka before resuming it
|
|
595
|
+
this.consumer.on(this.consumer.events.CONNECT, async () => {
|
|
596
|
+
this.consumer.resume(topicPartitions);
|
|
597
|
+
});
|
|
598
|
+
} else {
|
|
599
|
+
log.debug('Keep pausing consumer until IAP apps are active');
|
|
600
|
+
// wait for the consumer to connect to Kafka before pausing it
|
|
601
|
+
this.consumer.on(this.consumer.events.CONNECT, async () => {
|
|
602
|
+
this.consumer.pause(topicPartitions);
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
}, intTime);
|
|
606
|
+
}
|
|
607
|
+
await this.consumer.run({
|
|
608
|
+
eachMessage: async ({ topic, partition, message }) => {
|
|
609
|
+
log.info(`PROCESSING NEW MESSAGE ON TOPIC: ${topic} PARTITION: ${partition} WITH OFFSET: ${message.offset}`);
|
|
610
|
+
const newMsg = message;
|
|
611
|
+
let avroUsed = false;
|
|
612
|
+
let desiredTopic = [];
|
|
613
|
+
let allowedPartition = false;
|
|
614
|
+
|
|
615
|
+
// if using avro
|
|
616
|
+
if (this.registry && avroUsed) {
|
|
617
|
+
// will give us an interval between 5001 and 60000 milliseconds (5 seconds to 1 minute)
|
|
618
|
+
const fastInt = Math.floor(Math.random() * 55000) + 5001;
|
|
619
|
+
|
|
620
|
+
// This interval is to help prevent the adapter from bombarding the registry by sending requests at random intervals
|
|
621
|
+
const intervalObject = setInterval(async () => {
|
|
622
|
+
// Prevents running the request while the first one is running
|
|
623
|
+
if (!firstRun) {
|
|
624
|
+
if (!firstDone) {
|
|
625
|
+
firstRun = true;
|
|
626
|
+
}
|
|
582
627
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}, fastInt);
|
|
598
|
-
}
|
|
599
|
-
// find the topic here to change the offset
|
|
600
|
-
for (let t = 0; t < this.topicsEvents.length; t += 1) {
|
|
601
|
-
if (this.topicsEvents[t].topic === topic && (this.topicsEvents[t].partition === partition || this.topicsEvents[t].partition.includes(partition))) {
|
|
602
|
-
allowedPartition = true;
|
|
603
|
-
if (this.topicsEvents[t].offset < message.offset) {
|
|
604
|
-
this.topicsEvents[t].offset = message.offset;
|
|
605
|
-
}
|
|
606
|
-
// determine if we are using AVRO and set flag
|
|
607
|
-
if (this.topicsEvents[t].avro && this.topicsEvents[t].avro.toUpperCase() === 'YES') {
|
|
608
|
-
avroUsed = true;
|
|
609
|
-
}
|
|
610
|
-
// set desired topic for messages passing filtering
|
|
611
|
-
if (this.topicsEvents[t].subInfo) {
|
|
612
|
-
for (let k = 0; k < this.topicsEvents[t].subInfo.length; k += 1) {
|
|
613
|
-
let passesFiltering = true;
|
|
614
|
-
if (this.topicsEvents[t].subInfo[k].filters) {
|
|
615
|
-
passesFiltering = isPassingFiltering(topic, newMsg, this.topicsEvents[t].subInfo[k].filters);
|
|
628
|
+
try {
|
|
629
|
+
log.debug('GET AVRO KEY');
|
|
630
|
+
newMsg.key = await this.registry.decode(newMsg.key);
|
|
631
|
+
log.debug(`AVRO KEY: ${newMsg.key}`);
|
|
632
|
+
newMsg.value = await this.registry.decode(newMsg.value);
|
|
633
|
+
log.debug(`AVRO MSG: ${newMsg.value}`);
|
|
634
|
+
firstDone = true;
|
|
635
|
+
firstRun = false;
|
|
636
|
+
clearInterval(intervalObject);
|
|
637
|
+
} catch (ex) {
|
|
638
|
+
log.warn(`Had issue getting registry will try again in ${fastInt} milliseconds`);
|
|
639
|
+
firstRun = false;
|
|
616
640
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
641
|
+
}
|
|
642
|
+
}, fastInt);
|
|
643
|
+
}
|
|
644
|
+
// find the topic here to change the offset
|
|
645
|
+
for (let t = 0; t < this.topicsEvents.length; t += 1) {
|
|
646
|
+
if (this.topicsEvents[t].topic === topic && (this.topicsEvents[t].partition === partition || this.topicsEvents[t].partition.includes(partition))) {
|
|
647
|
+
allowedPartition = true;
|
|
648
|
+
if (this.topicsEvents[t].offset < message.offset) {
|
|
649
|
+
this.topicsEvents[t].offset = message.offset;
|
|
650
|
+
}
|
|
651
|
+
// determine if we are using AVRO and set flag
|
|
652
|
+
if (this.topicsEvents[t].avro && this.topicsEvents[t].avro.toUpperCase() === 'YES') {
|
|
653
|
+
avroUsed = true;
|
|
654
|
+
}
|
|
655
|
+
// set desired topic for messages passing filtering
|
|
656
|
+
if (this.topicsEvents[t].subInfo) {
|
|
657
|
+
for (let k = 0; k < this.topicsEvents[t].subInfo.length; k += 1) {
|
|
658
|
+
let passesFiltering = true;
|
|
659
|
+
if (this.topicsEvents[t].subInfo[k].filters) {
|
|
660
|
+
passesFiltering = isPassingFiltering(topic, newMsg, this.topicsEvents[t].subInfo[k].filters);
|
|
661
|
+
}
|
|
662
|
+
if (this.topicsEvents[t].subInfo[k].rabbit && passesFiltering) {
|
|
663
|
+
desiredTopic.push(this.topicsEvents[t].subInfo[k].rabbit);
|
|
664
|
+
} else if (passesFiltering) {
|
|
665
|
+
desiredTopic.push(this.topicsEvents[t].topic);
|
|
666
|
+
}
|
|
621
667
|
}
|
|
622
668
|
}
|
|
669
|
+
break;
|
|
623
670
|
}
|
|
624
|
-
break;
|
|
625
671
|
}
|
|
626
|
-
}
|
|
627
672
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
if (this.props.parseMessage || this.props.parseMessage === undefined) {
|
|
638
|
-
let messageObj;
|
|
639
|
-
const wrapper = this.props.wrapMessage || 'payload';
|
|
640
|
-
try {
|
|
641
|
-
messageObj = { [wrapper]: JSON.parse(newMsg.value) };
|
|
642
|
-
} catch (ex) {
|
|
643
|
-
messageObj = { [wrapper]: newMsg.value.toString() };
|
|
673
|
+
if (desiredTopic.length !== 0 && allowedPartition) {
|
|
674
|
+
log.info(`Message: '${message.value.toString()}' being CONSUMED as it does meet the filter condition`);
|
|
675
|
+
if (desiredTopic.every((val) => mytopics.includes(val))) {
|
|
676
|
+
log.info(`Emitting: ${message.value.toString()} TO ${desiredTopic}`);
|
|
677
|
+
} else {
|
|
678
|
+
log.info(`The desired topic ${desiredTopic} does not exist. If it should, make sure it is in pronghorn.json`);
|
|
679
|
+
log.info(`Emitting: ${newMsg.value.toString()} TO kafka`);
|
|
680
|
+
desiredTopic = 'kafka';
|
|
644
681
|
}
|
|
645
|
-
|
|
646
|
-
messageObj
|
|
647
|
-
|
|
682
|
+
if (this.props.parseMessage || this.props.parseMessage === undefined) {
|
|
683
|
+
let messageObj;
|
|
684
|
+
const wrapper = this.props.wrapMessage || 'payload';
|
|
685
|
+
try {
|
|
686
|
+
messageObj = { [wrapper]: JSON.parse(newMsg.value) };
|
|
687
|
+
} catch (ex) {
|
|
688
|
+
messageObj = { [wrapper]: newMsg.value.toString() };
|
|
689
|
+
}
|
|
690
|
+
for (let j = 0; j < desiredTopic.length; j += 1) {
|
|
691
|
+
messageObj.topic = topic;
|
|
692
|
+
eventSystem.publish(desiredTopic[j], messageObj);
|
|
693
|
+
}
|
|
694
|
+
} else {
|
|
695
|
+
for (let j = 0; j < desiredTopic.length; j += 1) {
|
|
696
|
+
newMsg.topic = topic;
|
|
697
|
+
eventSystem.publish(desiredTopic[j], newMsg);
|
|
698
|
+
}
|
|
648
699
|
}
|
|
649
700
|
} else {
|
|
650
|
-
|
|
651
|
-
newMsg.topic = topic;
|
|
652
|
-
eventSystem.publish(desiredTopic[j], newMsg);
|
|
653
|
-
}
|
|
701
|
+
log.info(`Message: '${newMsg.value.toString()}' being DROPPED as it fails to meet any filter condition`);
|
|
654
702
|
}
|
|
655
|
-
} else {
|
|
656
|
-
log.info(`Message: '${newMsg.value.toString()}' being DROPPED as it fails to meet any filter condition`);
|
|
657
703
|
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
run().catch((err) => console.error(`[consumer] ${err.message}`, err));
|
|
704
|
+
});
|
|
705
|
+
};
|
|
706
|
+
run().catch((err) => console.error(`[consumer] ${err.message}`, err));
|
|
662
707
|
|
|
663
|
-
|
|
664
|
-
|
|
708
|
+
const errorTypes = ['unhandledRejection', 'uncaughtException'];
|
|
709
|
+
const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2'];
|
|
665
710
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
711
|
+
errorTypes.forEach((type) => {
|
|
712
|
+
process.on(type, async (e) => {
|
|
713
|
+
try {
|
|
714
|
+
console.log(`process.on ${type}`);
|
|
715
|
+
console.error(e);
|
|
716
|
+
await this.consumer.disconnect();
|
|
717
|
+
process.exit(0);
|
|
718
|
+
} catch (_) {
|
|
719
|
+
process.exit(1);
|
|
720
|
+
}
|
|
721
|
+
});
|
|
676
722
|
});
|
|
677
|
-
});
|
|
678
723
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
724
|
+
signalTraps.forEach((type) => {
|
|
725
|
+
process.once(type, async () => {
|
|
726
|
+
try {
|
|
727
|
+
await this.consumer.disconnect();
|
|
728
|
+
} finally {
|
|
729
|
+
process.kill(process.pid, type);
|
|
730
|
+
}
|
|
731
|
+
});
|
|
686
732
|
});
|
|
687
|
-
})
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
733
|
+
} catch (ex) {
|
|
734
|
+
const errorObj = formatErrorObject(origin, 'Caught Exception', null, null, null, ex);
|
|
735
|
+
log.error(JSON.stringify(ex));
|
|
736
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
737
|
+
return (null, errorObj);
|
|
738
|
+
}
|
|
739
|
+
} else {
|
|
740
|
+
log.debug('Waiting for adapter to come back up');
|
|
693
741
|
}
|
|
694
742
|
}
|
|
695
743
|
|
package/package.json
CHANGED
|
Binary file
|