Confluent Kafka configure initial connection retry timeout
Asked Answered
P

0

6

I have a go project with confluent Kafka and I want to change it's initial connection timeout. If the kafka is not available on the first try I want to retry connecting to it every few seconds and give up retrying after 10 min.

By default it is repeatedly trying to connect to Kafka without break, I am getting the following log over again: [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv6#[::1]:9092 failed: Connection refused (after 1ms in state CONNECT) (sometimes lightly different eg ipv4 instead of ipv6 and 0ms or 2ms instead of 1ms)

I've tried the following configurations but none of them seems to work

    conf := kafka.ConfigMap{
        "bootstrap.servers":      fmt.Sprintf("%s:%d", kafkaHost, kafkaPort),
        "group.id":               "billing",
        "auto.offset.reset":      "earliest",
        "go.logs.channel.enable": true,

        "heartbeat.interval.ms":              10000,
        "session.timeout.ms":                 10000,
        "connections.max.idle.ms":            10000,
        "max.poll.interval.ms":               10000,
        "socket.connection.setup.timeout.ms": 10000,
        "auto.commit.interval.ms":            10000,
        "metadata.max.age.ms":                100000,
        "reconnect.backoff.max.ms":           100000,
        "reconnect.backoff.ms":               10000,
    }

I am able to connect to Kafka normally when it is running in a docker compose. Right now I only want to handle the case when it's down.

Paraprofessional answered 8/12, 2022 at 10:45 Comment(2)
Btw, you should support a CSV list for bootstrap.servers, but in my experience, there isn't a wait for give up retrying connection, but your reconnect.backoff.max.ms is currently set to 100 seconds, not 10 minutesJugurtha
I found a hacky workaround for now. I monitor connection error logs and when there are enough of them I call .Consumer.Close().Paraprofessional

© 2022 - 2025 — McMap. All rights reserved.