fix issue

This commit is contained in:
joy.zhou
2019-09-30 11:04:46 +08:00
parent e74b9facd1
commit a3fc611615
7 changed files with 31 additions and 19 deletions
+8 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"io/ioutil"
"strings"
"time"
"github.com/Shopify/sarama"
"go.uber.org/zap"
@@ -109,11 +110,17 @@ func (k *kafka) publish(topics map[string]bool, key string, msg *Elements) error
}
for topic, _ := range topics {
k.kafkaClient.Input() <- &sarama.ProducerMessage{
select {
case k.kafkaClient.Input() <- &sarama.ProducerMessage{
Topic: topic,
Key: sarama.ByteEncoder(key),
Value: sarama.ByteEncoder(payload),
}:
continue
case <-time.After(5 * time.Second):
return errors.New("write kafka timeout")
}
}
return nil