duanleiliu7373 2016-11-16 21:29
浏览 879
已采纳

如何在Golang 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 ?

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.

  • 写回答

1条回答 默认 最新

  • douxi7219 2016-11-21 15:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵