[英]Create multiple consumers for same topic in kafka
I am newbie and can see one example with one consumer in below github repository, but any ideas how to create multiple consumers for same topic in go lang? 我是新手,可以在github存储库下面看到一个包含一个使用者的示例,但是有什么想法如何在go lang中为同一主题创建多个使用者?
https://github.com/confluentinc/confluent-kafka-go/tree/master/examples https://github.com/confluentinc/confluent-kafka-go/tree/master/examples
Any consumer factory (to generate N consumers) available in confluent-kafka to read same topic (with partitions)? confluent-kafka中是否有任何消费者工厂(用于生成N个消费者)以读取相同主题(带有分区)?
There is an example in the Confluent github repo : 在Confluent github存储库中有一个示例:
https://github.com/confluentinc/confluent-kafka-go/blob/master/examples/consumer_example/consumer_example.go https://github.com/confluentinc/confluent-kafka-go/blob/master/examples/consumer_example/consumer_example.go
If you want to create multiple consumers for the same topic, there are two scenarios : 如果要为同一主题创建多个使用者,则有两种情况:
1.Create each consumer with different group id. 1.使用不同的组ID创建每个消费者。
c1, err := kafka.NewConsumer(&kafka.ConfigMap{
"bootstrap.servers": broker,
"group.id": group1,
"session.timeout.ms": 6000,
"default.topic.config": kafka.ConfigMap{"auto.offset.reset": "earliest"}})
c2, err := kafka.NewConsumer(&kafka.ConfigMap{
"bootstrap.servers": broker,
"group.id": group2,
"session.timeout.ms": 6000,
"default.topic.config": kafka.ConfigMap{"auto.offset.reset": "earliest"}})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.