Skip to content

Commit

Permalink
Exit on refresh metadata error
Browse files Browse the repository at this point in the history
  • Loading branch information
thspinto committed May 21, 2018
1 parent 2f1bada commit b4e58ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quintoandar-kafka",
"version": "0.0.7",
"version": "0.0.8",
"description": "Default Kafka NodeJS lib for QuintoAndar",
"main": "src/main.js",
"dependencies": {
Expand Down
14 changes: 8 additions & 6 deletions src/node-kafka-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class KafkaConsumer {
init() {
this.consumer = new kafka.ConsumerGroupStream(this.configs, this.topics);
this.consumer.on('error', (err) => {
logger.error(err);
logger.error('node-kafka error: ', err);
process.exit(1);
});

Expand All @@ -52,11 +52,13 @@ class KafkaConsumer {
this.consumer.consumerGroup.client.refreshMetadata(
this.consumer.consumerGroup.topics,
(err) => {
if (err && err.name === 'BrokerNotAvailableError') {
logger.warn(err);
this.consumer.close(() => {
this.init();
});
if (err) {
logger.warn('Refresh metadata error: ', err);
if (err.name === 'BrokerNotAvailableError') {
this.consumer.close(() => {
process.exit(1);
});
}
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions tests/node-kafka-consumer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ describe('Refresh metadata', () => {
consumer.consumer.close = jest.fn().mockImplementation((cb) => {
cb();
});
consumer.consumer.name = 'original-consumer';
global.process.exit = jest.fn();
consumer.refreshMetadata();
expect(consumer.consumer.name).toBe(undefined);
expect(global.process.exit).toHaveBeenCalledWith(1);
done();
});
});

0 comments on commit b4e58ee

Please sign in to comment.