如何在Golang Kafka 10中获得消费群组的分区补偿 [英] How to get consumer group offsets for partition in Golang Kafka 10

查看:1424
本文介绍了如何在Golang Kafka 10中获得消费群组的分区补偿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在Golang Kafka图书馆(sarama)提供消费者群组功能,而无需任何外部图书馆帮助与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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆