Search code examples
goapache-kafkasarama

How to get multiple subscriptions in sarama


Someone knows how to make a multi-subscription topics in Apache Kafka using Sarama

I have a simple consumer, and I need to subscribe to three different topics

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

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

Solution

  • Sarama Cluster helped for me

        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()