如何在 Golang Kafka 10 中获取分区的消费者组偏移量 [英] How to get consumer group offsets for partition in Golang Kafka 10

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

问题描述

现在 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.com/wvanbergen/kazoo-go) 来获取我的消费者组消息偏移量,因为它存储在 Zookeeper 中.现在我使用 sarama-cluster (https://github.com/bsm/sarama-cluster),我不确定使用哪个 API 来获取我的消费者组消息偏移量.

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.

推荐答案

我也在与 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屋!

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