Sarama Cluster Admin - Broker Connected method return false

723 views Asked by At

Versions

Sarama - v1.32.0
Kafka - 5.4.6-2.12
Go - v1.16.2

sarama.Logger = log.New(os.Stderr, "[Sarama] ", log.LstdFlags)
brokers := []string{
    "kafka1:9092",
    "kafka2:9092",
}

cfg := sarama.NewConfig()
cfg.Version = sarama.V2_4_0_0
admin, err := sarama.NewClusterAdmin(brokers, sarama.NewConfig())
if err != nil {
    log.Fatal(err)
}
brok, _, err := admin.DescribeCluster()
if err != nil {
    log.Fatal(err)
}
for _, b := range brok {
    chck, err := b.Connected()
    if err != nil {
        log.Fatal(err)
    }
    log.Println(chck)
}

I am trying to check whether the brokers are connected but it returns false for the method Connected(). If there an explanation on as why it returns false? I need to write a health check so my initial plan was to check whether the brokers were connected but any other checks I could do?

saramaConfig := sarama.NewConfig()
saramaConfig.Version = sarama.V2_0_0_0

client, err := sarama.NewClient(brokers, saramaConfig)
if err != nil {
    log.Fatal("NewKafkaAdmin", fmt.Sprintf(`cannot get controller - %+v`, err))
}
b, _ := client.Controller()
fmt.Println(b.Connected())

This return true. Why is that there is an mismatch of such?

1

There are 1 answers

0
Anjula Paulus On BEST ANSWER

This cannot be done using DescribeCluster method. A detailed explanation could be found in the following issue.

https://github.com/Shopify/sarama/issues/2222