简体   繁体   English

在kafka中为同一主题创建多个使用者

[英]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"}})
  1. If you want multiple consumers for the same topic but with the same group id, it will start consuming from single partition. 如果您希望多个使用者使用同一主题但具有相同的组ID,则它将从单个分区开始使用。 ie A topic contains 3 partitions and you create 3 consumers with same group id, each consumer will consume from one partition 即,一个主题包含3个分区,您创建了3个具有相同组ID的使用者,每个使用者将在一个分区中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM