繁体   English   中英

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

[英]Create multiple consumers for same topic in kafka

我是新手,可以在github存储库下面看到一个包含一个使用者的示例,但是有什么想法如何在go lang中为同一主题创建多个使用者?

https://github.com/confluentinc/confluent-kafka-go/tree/master/examples

confluent-kafka中是否有任何消费者工厂(用于生成N个消费者)以读取相同主题(带有分区)?

在Confluent github存储库中有一个示例:

https://github.com/confluentinc/confluent-kafka-go/blob/master/examples/consumer_example/consumer_example.go

如果要为同一主题创建多个使用者,则有两种情况:

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. 如果您希望多个使用者使用同一主题但具有相同的组ID,则它将从单个分区开始使用。 即,一个主题包含3个分区,您创建了3个具有相同组ID的使用者,每个使用者将在一个分区中使用

暂无
暂无

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

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