An available library is sarama (or its expansion sarama-cluster) however no consumer group example are provided, not in sarama nor in sarama-cluster.

我不了解API.我可以举一个为主题创建消费群体的例子吗?

I do not understand the API. May I have an example of creating a consumer group for a topic?

推荐答案

使用者组由群集使用者构造函数"的第二个参数指定.这是一个非常基本的草图:

The consumer group is specified by the second argument of the cluster consumer "constructor". Here's a very basic sketch:

import (
    "github.com/Shopify/sarama"
    "github.com/bsm/sarama-cluster"
)

conf := cluster.NewConfig()
// add config values

brokers := []string{"kafka-1:9092", "kafka-2:9092"}
group := "Your-Consumer-Group"
topics := []string{"topicName"}
consumer := cluster.NewConsumer(broker, group, topics, conf)

因此,您将拥有一个属于指定消费者组的消费者.

And so you'll have a consumer belonging to the specified consumer group.

这篇关于如何在Golang中创建一个kafka消费者组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!