2016-11-16 21:29
浏览 723

如何在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.

图片转代码服务由CSDN问答提供 功能建议

现在,Golang Kafka库(sarama)提供了消费者组功能,而kafka 10没有任何外部库帮助。 在任何给定时间,我都会得到消费者组正在处理的当前消息偏移量?

以前,我使用过kazoo-go( https://github.com/wvanbergen/kazoo-go )来获取我的消费者组消息,因为它存储在Zookeeper中。 现在,我使用sarama-cluster( https://github.com/bsm/sarama-cluster ),我不确定要使用哪个API来抵消使用者组消息的偏移量。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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 (
        func main(){
          client , err := sarama.Client([]string{"localhost:9092"},nil) // I am not giving any configuration
          if err != nil {
          lastoffset, err := client.GetOffset("topic-test",0,sarama.OffsetNewest)
          if err != nil {
          fmt.Println("Last Commited Offset ",lastoffset)

    Let me know if this is the answer you are looking for and if it is helpful.

    解决 无用
    打赏 举报

相关推荐 更多相似问题