3

I have a Kafka ConsumerGroup (Golang/Segmentio) with one reader as part of unit test cases

r := kafka.NewReader(kafka.ReaderConfig{
        Brokers:        []string{"localhost:9092"},
        Topic:          "test",
        CommitInterval: time.Second, // flushes commits to Kafka every second
        MaxWait:        10 * time.Millisecond,
        GroupID:        "test_logs",
        StartOffset:    kafka.LastOffset,
    })

Reader is able to read the messages but after reading all the messages from the topic it is waiting for new messages and the test case is timing out after 30s.

If I set the context.WithTimeout(ctx, 20*time.Second), then the reader is not able to read any messages from the topic.

So how can I read the messages from the topic and proceed instead of waiting for the new messages.

Jem Tucker
  • 1,143
  • 16
  • 35

0 Answers0