如何在Golang Kafka 10中获得消费群组的分区补偿 [英] How to get consumer group offsets for partition in Golang Kafka 10
问题描述
以前我使用过kazoo-go( https://github.com/ wvanbergen / kazoo-go )以获取我的消费者群组消息,因为它存储在Zookeeper中。现在我使用sarama-cluster( https://github.com/bsm/sarama-cluster ),我不确定使用哪个API来获取消费者组消息的偏移量。
我也在和Sarama合作, Kafka可以抵消一个主题。
您可以使用以下代码获得抵消额。
包主
导入(
gopkg.in/Shopify/sarama
fmt
)
func main(){
client,err:= sarama.Client([] string {localhost:9092},nil)//我没有给出任何配置
if err!= nil {
panic(err)
}
lastoffset,err:= client.GetOffset(topic-test,0,sarama.OffsetNewest)
if err!= nil {
恐慌(错误)
}
fmt.Println(最后一次抵消,lastoffset)
}
让我知道这是否是你正在寻找的答案,是否有帮助。
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 ?
Previously I used kazoo-go (https://github.com/wvanbergen/kazoo-go) to get my consumer group message offset as it is stored in Zookeeper. Now I use sarama-cluster (https://github.com/bsm/sarama-cluster), I am not sure which API to use to get my consumer group message offset.
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屋!