kafka-go
kafka-go copied to clipboard
Question: Is this the right way to ping the Kafka cluster?
Hello,
My team is making use of this library's kafka.Reader object.
My team wanted to do the equivalent of pinging the Kafka cluster before continuing with program execution -- we came up with this:
func BlockUntilConnectionToKafkaClusterMade(reader *kafka.Reader) {
for {
logrus.Info("Waiting for connection to Kafka Cluster to be made...")
fetches := reader.Stats().Fetches
if fetches > 0 {
logrus.Info("Connection to kafka cluster successful.")
break
}
time.Sleep(time.Second)
}
}
We aren't sure if Fetches is only greater than 0 if a successful connection is made.
We assume that if a connection cannot be made that fetches will remain at 0 indefinitely.
We would appreciate if someone more knowledgeable as to the inner workings of kafka-go could confirm/deny this assumption.