Skip to content

Instantly share code, notes, and snippets.

@TonPC64
Created February 24, 2022 14:50
Show Gist options
  • Save TonPC64/69c92f089de7c4fc8872de04474ee53a to your computer and use it in GitHub Desktop.
Save TonPC64/69c92f089de7c4fc8872de04474ee53a to your computer and use it in GitHub Desktop.
func main() {
startConsumerGroup([]string{"kafka:9092"})
select {}
}
func startConsumerGroup(brokerList []string) {
consumerGroupHandler := Consumer{}
// Wrap instrumentation
handler := otelsarama.WrapConsumerGroupHandler(&consumerGroupHandler)
config := sarama.NewConfig()
config.Version = sarama.V2_5_0_0
config.Consumer.Offsets.Initial = sarama.OffsetOldest
// Create consumer group
consumerGroup, err := sarama.NewConsumerGroup(brokerList, "example", config)
if err != nil {
log.Fatalln("Failed to start sarama consumer group:", err)
}
err = consumerGroup.Consume(context.Background(), []string{"example-topic"}, handler)
if err != nil {
log.Fatalln("Failed to consume via handler:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment