I'm using sarama-cluster
lib to create a kafka group consumer, in a backend service. This example code from godoc works:
for {
if msg, ok := <-consumer.Messages(); ok {
fmt.Fprintf(os.Stdout, "%s/%d/%d\t%s\t%s\n", msg.Topic, msg.Partition, msg.Offset, msg.Key, msg.Value)
consumer.MarkOffset(msg, "") // mark message as processed
}
}
since it's a dead loop, I put it in a goroutine to avoid blocking other activities, then it can no longer consume any message:
go func() {
for msg := range consumer.Messages() {
fmt.Fprintf(os.Stdout, "%s/%d/%d\t%s\t%s\n", msg.Topic, msg.Partition, msg.Offset, msg.Key, msg.Value)
consumer.MarkOffset(msg, "") // mark message as processed
}
}()
(service is running, so this goroutine is not terminated. It just fails to consume)
Any idea how to solve this?