Skip to content

Commit

Permalink
Fix msg in error logger in handleMessageFn (#12)
Browse files Browse the repository at this point in the history
* Fix and improve error logs in consumer

* update lib ver
  • Loading branch information
bruno-kenji authored May 21, 2019
1 parent 0ae30f4 commit 967c365
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Standard node consumer/producer implementation for QuintoAndar.

## Examples

See [exemples folder](/example)
See [examples folder](/example)

## Configuration

Checkout [kafka-node repo](https://github.com/SOHU-Co/kafka-node) for configuration info.
Checkout [kafka-node repo](https://github.com/SOHU-Co/kafka-node) for configuration info.
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.2.2",
"version": "0.2.3",
"description": "Default Kafka NodeJS lib for QuintoAndar",
"main": "src/main.js",
"types": "types/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions src/node-kafka-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ class KafkaConsumer {
init() {
this.consumer = new kafka.ConsumerGroupStream(this.configs, this.topics);
this.consumer.on('error', (err) => {
logger.error('node-kafka error: ', err);
logger.error('node-kafka error:', err);
process.exit(1);
});

this.consumer.on('data', (msg) => {
this.handleMessageFn(msg).then(() => {
this.consumer.commit(msg, true);
}).catch((err) => {
logger.error(`Consumer error on handleMessageFn: ${err}.
The following message was not committed: ${msg}`);
logger.error(
'The following message was not committed:', msg,
'Consumer error on handleMessageFn:', err
);
});
});

Expand All @@ -58,7 +60,7 @@ class KafkaConsumer {
this.consumer.consumerGroup.topics,
(err) => {
if (err) {
logger.warn('Refresh metadata error: ', err);
logger.warn('Refresh metadata error:', err);
if (err.name === 'BrokerNotAvailableError') {
this.consumer.close(() => {
process.exit(1);
Expand Down

0 comments on commit 967c365

Please sign in to comment.