Skip to content

Commit

Permalink
Make kafkahook.Fire never block
Browse files Browse the repository at this point in the history
  • Loading branch information
horkhe committed Dec 6, 2017
1 parent 5ee121b commit 90e3206
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kafkahook/kafkahook.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func New(conf Config) (*KafkaHook, error) {
kafkaConfig.Producer.Flush.Frequency = 200 * time.Millisecond
kafkaConfig.Producer.Retry.Backoff = 10 * time.Second
kafkaConfig.Producer.Retry.Max = 6
kafkaConfig.Producer.Return.Errors = true

// If the user failed to provide a producer create one
if conf.Producer == nil {
Expand Down Expand Up @@ -111,8 +110,10 @@ func (h *KafkaHook) sendKafka(buf []byte) error {
Topic: h.topic,
Key: nil,
}:
case err := <-h.producer.Errors():
return err
default:
// If the producer input channel buffer is full, then we better drop
// a log record than block program execution.
fmt.Fprintf(os.Stderr, "kafkahook buffer overflow: %s\n", string(buf))
}
return nil
}
Expand Down

0 comments on commit 90e3206

Please sign in to comment.