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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器