英文:
Sarama Cluster Admin - Broker Connected method return false
问题
版本
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)
}
我正在尝试检查代理是否连接,但是Connected()方法返回false。是否有解释为什么会返回false?我需要编写一个健康检查,所以我的初始计划是检查代理是否连接,但还有其他检查可以进行吗?
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())
这将返回true。为什么会出现这种不匹配?
英文:
Versions
Sarama - v1.32.0 <br>
Kafka - 5.4.6-2.12 <br>
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
得分: 0
这不能通过使用DescribeCluster方法来完成。可以在以下问题中找到详细的解释。
https://github.com/Shopify/sarama/issues/2222
英文:
This cannot be done using DescribeCluster method. A detailed explanation could be found in the following issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论