如何在sarama中获得多个订阅

时间:2018-05-28 14:37:12

标签: go apache-kafka sarama

有人知道如何使用Sarama在Apache Kafka中创建多订阅主题

我有一个简单的消费者,我需要订阅三个不同的主题

topic := "Payments" // need to be "Payments","System","Orders"

consumer, err := master.ConsumePartition(topic, 0, sarama.OffsetOldest)
if err != nil {
    panic(err)
}

1 个答案:

答案 0 :(得分:0)

Sarama Cluster对我有帮助

    brokers := []string{"127.0.0.1:9092"}
    topics := []string{"my_topic", "other_topic"}
    consumer, err := cluster.NewConsumer(brokers, "my-consumer-group", topics, config)
    if err != nil {
        panic(err)
    }
    defer consumer.Close()