Skip to content

Commit

Permalink
rety
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey committed Aug 16, 2024
1 parent b46085d commit 0caf1d9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions kafka/resource_kafka_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,19 @@ func testResourceTopic_produceMessages(messages []*sarama.ProducerMessage) r.Tes
}
}()

if errs := producer.SendMessages(messages); errs != nil {
for _, err := range errs.(sarama.ProducerErrors) {
log.Println("[ERROR] Write to kafka failed: ", err)
return err
// rety 5 times
retries := 5
for i := 0; i < retries; i++ {
if errs := producer.SendMessages(messages); errs != nil {
for _, err := range errs.(sarama.ProducerErrors) {
log.Println("[ERROR] Write to kafka failed: ", err)
if i == retries-1 {
return err
}
}
} else {
return nil
}
return errs

}

return nil
Expand Down

0 comments on commit 0caf1d9

Please sign in to comment.