oleksiyk / kafka

Apache Kafka 0.9 client for Node
MIT License
297 stars 85 forks source link

Simple Consumer Failed to Connect to Broker #215

Closed iicervantes closed 6 years ago

iicervantes commented 6 years ago

Currently, when a simple consumer attempts to connect to a broker but for some reason it cannot connect, no-kafka tries to connect, according to reconnectionDelay. Other than reading logs, there is no way to catch the "NoKafkaConnectionError" error when running consumer.init(). The promise for this function is never rejected and hence I cannot move forward.

ERROR no-kafka-client Metadata request failed: NoKafkaConnectionError [hostname:port]: Connection timeout { [NoKafkaConnectionError: Connection timeout] name: 'NoKafkaConnectionError', server: 'hostname:port', message: 'Connection timeout' }

--This is the error is that spits out when pointing to a broker that is down.

Is there any way to catch this error? Annoyingly, it fills up my logs.

oleksiyk commented 6 years ago

Use Promise.race([]) for init() call with timeout in your code.

iicervantes commented 6 years ago

Only problem with this workaround is that the logs are going to get filled with the same error since it wont stop to reconnect. It would be nice for the consumer to have a "retriesAttempt" option like the producer. Say you know a broker will be down for certain amount of hours, there's no point in trying to reconnect.

This will do for now. Thanks for the support!