go - 解释 GetMetadata 参数
问题描述
作为函数的文档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)
}
所以我猜如果主题不是零,结果总是只返回特定的主题信息。但是,当我尝试测试时,我看到了非常奇怪的结果。
假设我已经有一个 Kafka 主题。然后我将该方法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_kafka_metadata
or _getMetadata_broker_element
。但是我很难理解这些功能。
我用 3 个代理在 Kafka 集群上进行了测试。请为我解释背后的逻辑是什么。
解决方案
推荐阅读
- json - jsonb[] vs jsonb,其中 json 是一个数组
- jquery - Jquery DataTable 插件没有效果
- reactjs - 反应js中的方法覆盖
- sql - 实现基于值范围的颜色查找 SQL 表
- vaadin - Vaadin-CDI 缺少 Bundle-ManifestVersion
- r - 如何通过在R中搜索特定字母和字母顺序来重命名变量并将其更改为另一个变量
- azure-devops - 使用 Fortify on Demand 进行身份验证时出错。错误:错误:无法验证第一个证书
- c# - 这个活动图是否很好地显示了我的方法是如何工作的?
- python - 对 CX_ORACLE 的 SQL INSERT 语句使用 Python dict
- vue.js - 如何在 Nuxt JS 中将 vuetify 更新到最新版本?