Sarama Cluster Admin – Broker Connected方法返回false。

huangapple go评论89阅读模式
英文:

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, &quot;[Sarama] &quot;, log.LstdFlags)
brokers := []string{
	&quot;kafka1:9092&quot;,
	&quot;kafka2:9092&quot;,
}

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(&quot;NewKafkaAdmin&quot;, 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.

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

huangapple
  • 本文由 发表于 2022年5月6日 19:40:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/72140890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定