Commit 205d3cd7 authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch '8-loose-of-connections' into 'master'

Better error logging and exit on fatal errors

Closes #8

See merge request !21
parents c37480a9 0017847f
Pipeline #2795 passed with stage
in 2 minutes and 39 seconds
......@@ -50,6 +50,7 @@ app.get('/v1/', HealthcheckController.healthy);
*/
const kafka = core.getKafkaAvro();
kafka.init().then(async () => {
const logger = core.getLogger();
const consumer = await kafka.getConsumer();
const producer = await kafka.getProducer();
await consumer.connect();
......@@ -66,17 +67,25 @@ kafka.init().then(async () => {
// emit a separate event for each key. The key is the identifier for the request
// todo:we need some unique id. otherwise there are too many listeners
if(!kafkaEventEmitter.emit(`data-${rawData.parsed.id}`, rawData.parsed)) {
console.log(`Error: No listener for event data-${rawData.parsed.id}`)
logger.warn(`Error: No listener for event data-${rawData.parsed.id}`)
}
});
/**
* Exit on error
*/
consumer.on('error', function(err) {
console.error('Kafka consumer stream error', err);
logger.error('Kafka consumer stream error', err);
process.exit(1);
});
/**
* Warn in transport error
*/
consumer.on('event.error', function(err) {
console.log('Kafka consumer event error', err); // Here this error being logged
logger.warn('Kafka consumer event error', err); // Here this error being logged
});
/**
* Small middleware to inject kafka into the middlewar-stack
* @param {InterfaceRequestApi} req
......
......@@ -11,4 +11,8 @@ export class HealthcheckController {
public static healthy(req: Request, res: Response, next: NextFunction) {
return res.sendStatus(200);
}
/**
* todo: add a healthcheck for the kafka connection
*/
}
......@@ -7,5 +7,6 @@ kafkaEventEmitter.setMaxListeners(100);
kafkaEventEmitter.on('error', (err) => {
console.error('There was an error in the kafkaEventEmitter');
console.error(err);
process.exit(1);
});
export default kafkaEventEmitter;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment