segmentio / kafka-go

Kafka library in Go
MIT License
7.3k stars 760 forks source link

Should retry when the error occurs.kafka.(*Client).Produce: fetch request error: topic partition has no leader #1288

Open stonever opened 1 month ago

stonever commented 1 month ago

Describe the bug

Kafka is encountering this error for some reason, but the client should support retries. I have configured the number of retries, but it is not working.

My code:

w := &kafka.Writer{
        Addr:                   kafka.TCP(option.Broker...),
        Topic:                  topic,
        Balancer:               &kafka.Hash{},
        Async:                  true,
        RequiredAcks:           kafka.RequireAll,
        Transport:              transport,
        MaxAttempts:            100,
        AllowAutoTopicCreation: true,
        Logger: kafka.LoggerFunc(func(s string, i ...interface{}) {
            log.With(ctx).Info().Msgf(s, i...)
        }),
        ErrorLogger: kafka.LoggerFunc(func(s string, i ...interface{}) {
            log.With(ctx).Error().Msgf(s, i...)
        }),
    }