dousui6193 2019-04-07 21:31
浏览 191

回收kafka时,需要重新创建/恢复Sarama Producer

I have created Kafka Producer using sarama with below code.

var producer sarama.AsyncProducer //...this is Global declaration

config := sarama.NewConfig()
//config.Producer.Return.Successes = false
//config.Producer.Partitioner = sarama.NewRandomPartitioner
//config.Producer.RequiredAcks = sarama.WaitForLocal       
config.Producer.Compression = sarama.CompressionSnappy   
config.Producer.Flush.Frequency = 100 * time.Millisecond 
producer, errsar = sarama.NewAsyncProducer([]string{"x.x.x.x:9091"}, config)
if errsar != nil {
    panic(errsar)
}

Everything works fine, but when i reboot my kafka .. i get error " partition in middle of leadership election..." . When i restart my app, which effectively is restarting producer everything works fine.

Is there an option in Sarama where it would not give me the parition error when i restart kafka and start sending messages ( confluent doesnt have this problem.. it works well. But sarama gives us better performance)

Any help is appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?