0

I have three brokers running on 9002, 9003 and 9004 port . Now i am using kafkajs npm library to create a consumer. Now in the ideal scenario when all the brokers are down at that time i am getting below error -

{"level":"ERROR","timestamp":"2023-03-17T15:07:06.849Z","logger":"kafkajs","message":"[Consumer] Crash: KafkaJSNonRetriableError: Connection error: connect ECONNREFUSED 127.0.0.1:9094","groupId":"groupId","stack":"KafkaJSNonRetriableError: Connection error: connect ECONNREFUSED 127.0.0.1:9094\n    at /Users/vn54q4d/projects/path/node_modules/kafkajs/src/retry/index.js:53:18\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

and my consumer shut down and stop consuming the data from topic. So actually i want to solve that if after some time all of my broker are again up and running then either ,

  1. consumer should automatically get started and start consuming the data in the queue, or
  2. consumer should not shutdown when all the brokers are down.
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
lal rishav
  • 549
  • 3
  • 5
  • 17

1 Answers1

1

You need to use a while loop around your consumer.connect() call to attempt a reconnection. Otherwise, KafkaJS already has its own limited connection-retry logic.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245