Open nenadlazovic opened 3 years ago
I'm facing into the same issue, where our app starts, if the consumer is down, the app crashes. I'm looking for / looking to build a way of intermittently retrying kafka connections while the app runs, however no successes yet.
Attempting to put the connect in a try/catch block does get past the app exiting, however I'm looking for a way to attempt a reconnection after a given time period:
async connect() {
const kafka = new Kafka(this.options.client);
this.producer = kafka.producer();
try {
this.producer.connect();
} catch (err) {
setTimeout(async () => {
await this.producer.connect();
}, 1000 * 60 * 5); // retry connection every 5 minutes
}
}
This block unfortunately doesn't work as you'd expect.
Using Kafkajs 1.15.0.
Issue: ensure consumer / producer always keep reconnecting in all scenarios
Our app is mobile app that connects to Kafka cluster. App have 1 consumer / 1 producer . Network used to connect to brokers may go down. Connectivity to Kafka has to be maintained and re-established when Kafka cluster is accessible.
We noticed that
We would appreciate if you could answer
Current kafkajs init code is pretty standard ...
` async init(connStatusListener) { this.connStatusListener = connStatusListener;
`