dra11767 2017-02-01 16:17
浏览 628

如何在Golang Kafka 10中获取GroupID?

I am using Kafka 10.0 and https://github.com/Shopify/sarama. I am trying to get the offset of the latest message that a consumer processed.

To do so I've found the method NewOffsetManagerFromClient(group string, client Client) which require the group name.

How do I get consumer group name?

offsets := make(map[int32]int64)

config := sarama.NewConfig()
config.Consumer.Offsets.CommitInterval = 200 * time.Millisecond
config.Version = sarama.V0_10_0_0

// config.Consumer.Offsets.Initial = sarama.OffsetNewest
cli, _ := sarama.NewClient(kafkaHost, config)
defer cli.Close()

offsetManager, _ := sarama.NewOffsetManagerFromClient(group, cli)
for _, partition := range partitions {
    partitionOffsetManager, _ := offsetManager.ManagePartition(topic, partition)
    offset, _ := partitionOffsetManager.NextOffset()

    offsets[partition] = offset
}
return offsets

I created a consumer with

consumer := sarama.NewConsumer(connections, config)

but I do not know how to create a consumer group and get its group name.

  • 写回答

1条回答 默认 最新

  • duan5991518 2017-02-01 18:10
    关注

    You are attempting to create your own offset manager to find current offsets:

    offsetManager, _ := sarama.NewOffsetManagerFromClient(group, cli)
    

    Similarly, the consumer that was consuming your topic's messages would have to use the same offset manager and they would have used a specific group id. Use that group id.

    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?