问题描述
限时送ChatGPT账号..现在 Golang Kafka 库 (sarama) 正在提供消费者组功能,而无需任何外部库帮助 kafka 10.如何获取消费者组在任何给定时间正在处理的当前消息偏移量?
Now that Golang Kafka library (sarama) is providing consumer group capability without any external library help with kafka 10. How can I get the current message offset being processed by a consumer group at any given time ?
之前我用过 kazoo-go (https://github/wvanbergen/kazoo-go) 来获取我的消费者组消息偏移量,因为它存储在 Zookeeper 中.现在我使用 sarama-cluster (https://github/bsm/sarama-cluster),我不确定使用哪个 API 来获取我的消费者组消息偏移量.
Previously I used kazoo-go (https://github/wvanbergen/kazoo-go) to get my consumer group message offset as it is stored in Zookeeper. Now I use sarama-cluster (https://github/bsm/sarama-cluster), I am not sure which API to use to get my consumer group message offset.
推荐答案
我也在与 Sarama 和 Kafka 合作以获得主题的偏移.
I am also working with Sarama and Kafka to get offset of a topic.
您可以使用以下代码获得偏移量.
You can get offset with following code.
package main
import (
"gopkg.in/Shopify/sarama"
"fmt"
)
func main(){
client , err := sarama.Client([]string{"localhost:9092"},nil) // I am not giving any configuration
if err != nil {
panic(err)
}
lastoffset, err := client.GetOffset("topic-test",0,sarama.OffsetNewest)
if err != nil {
panic(err)
}
fmt.Println("Last Commited Offset ",lastoffset)
}
让我知道这是否是您正在寻找的答案以及它是否有帮助.
Let me know if this is the answer you are looking for and if it is helpful.
这篇关于如何在 Golang Kafka 10 中获取分区的消费者组偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论