Go 解释GetMetadata参数

Go 解释GetMetadata参数,go,apache-kafka,confluent-platform,librdkafka,Go,Apache Kafka,Confluent Platform,Librdkafka,作为函数GetMetaData: // GetMetadata queries broker for cluster and topic metadata. // If topic is non-nil only information about that topic is returned, else if // allTopics is false only information about locally used topics is returned, // else informa

作为函数
GetMetaData

// GetMetadata queries broker for cluster and topic metadata.
// If topic is non-nil only information about that topic is returned, else if
// allTopics is false only information about locally used topics is returned,
// else information about all topics is returned.
// GetMetadata is equivalent to listTopics, describeTopics and describeCluster in the Java API.
func (a *AdminClient) GetMetadata(topic *string, allTopics bool, timeoutMs int) (*Metadata, error) {
    return getMetadata(a, topic, allTopics, timeoutMs)
}
所以我猜如果主题是非零的,那么结果总是只返回特定的主题信息。然而,当我尝试测试时,我看到了非常奇怪的结果

假设我已经有了一个卡夫卡主题。然后我调用方法
GetMetadata
,如下代码所示:

topic := "sample_topic"
admin.GetMetadata(nil, false, timeout)
admin.GetMetadata(nil, true, timeout)
admin.GetMetadata(&topic, false, timeout)
admin.GetMetadata(&topic, true, timeout)
admin.GetMetadata(&topic,false,timeout)
返回主题信息。所有其他案例返回所有主题信息

但是,当测试集群中不存在的主题时,只有调用
admin.GetMetadata(&topic,false,timeout)
才会产生错误

data, err := admin.GetMetadata(&topic, false, admin.timeOutMs())
fmt.Println(data.Topics[topic]) //   Broker: Unknown topic or partition
重新排序代码时,结果也会更改

我阅读了源代码,发现它使用了
librdkafka
中的一些函数,例如
rd\u kafka\u metadata
\u getMetadata\u broker\u元素
。但我很难理解这些功能

我在卡夫卡集群上测试了3个代理。请给我解释一下背后的逻辑