How to properly communicate with multiple kafka brokers in segmentio's kafka-go?

Viewed 245

Field Brokers allows you to setup multiple hosts, but if one broker is down, the behavior is not as expected.

import "github.com/segmentio/kafka-go"


reader := kafka.NewReader(kafka.ReaderConfig{
    
    // The list of broker addresses used to connect to the kafka cluster
    Brokers: []string{"not_working_host:9092", "working_host:9092"},

    Topic:   "test_topic",
    Dialer: &kafka.Dialer{
        Timeout:   5 * time.Second,
    },
})

for i := 1; i <= 10; i++ {
    reader.ReadLag(context.Background())
}

In this case, I get a freeze for 5 seconds on every call. Reader does not remember the last successful connection. So how to accommodate the possibility that one of the brokers (first in the list) can die in runtime?

0 Answers
Related