问题
We are using kafka-streams 2.3.1 and I've just noticed that if broker is down, the streams app seems to be content to try to keep trying connecting forever.
new KafkaStreams(createTopology(), properties()).start()
o.apache.kafka.clients.NetworkClient - [AdminClient clientId=test] Connection to node -1 (broker/127.0.0.1:9092) could not be established. Broker may not be available.
The streams state is REBALANCING while this is going on so there's no good way to determine if the connection is just broken.
Is there a way to set either a timeout or a number of retries for broker(s) connection attempts?
回答1:
There is unfortunately no good workaround for this problem. The issue is actually a consumer issue, as the consumer just tries to reconnect but does not surface it's internal state to Kafka Streams. Also, it's not possible to configure the consumer to give up at some point.
There is a KIP to add a "DISCONNECTED" state to Kafka Streams, but there was not much progress lately... It's complicated... https://cwiki.apache.org/confluence/display/KAFKA/KIP-457%3A+Add+DISCONNECTED+status+to+Kafka+Streams
来源:https://stackoverflow.com/questions/59403196/kafka-streams-broker-connection-timeout-setting