Created
February 24, 2022 14:50
-
-
Save TonPC64/69c92f089de7c4fc8872de04474ee53a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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