如何在 Golang Kafka 10 中获取分区的消费者组偏移量

编程入门 行业动态 更新时间:2024-10-26 14:36:38
本文介绍了如何在 Golang Kafka 10 中获取分区的消费者组偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

Previously I used kazoo-go (https://github/wvanbergen/kazoo-go) to get my consumer group message offset as it is stored in Zookeeper. Now I use sarama-cluster (https://github/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 13:34:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/963139.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分区   消费者   偏移量   如何在   Golang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!