Kafka output fixup

This commit is contained in:
Cameron Sparr 2016-12-06 15:38:59 +00:00
parent d71a42cd1b
commit a093ec1eaa
1 changed files with 11 additions and 14 deletions

View File

@ -154,26 +154,23 @@ func (k *Kafka) Write(metrics []telegraf.Metric) error {
}
for _, metric := range metrics {
values, err := k.serializer.Serialize(metric)
buf, err := k.serializer.Serialize(metric)
if err != nil {
return err
}
var pubErr error
for _, value := range values {
m := &sarama.ProducerMessage{
Topic: k.Topic,
Value: sarama.StringEncoder(value),
}
if h, ok := metric.Tags()[k.RoutingTag]; ok {
m.Key = sarama.StringEncoder(h)
}
_, _, pubErr = k.producer.SendMessage(m)
m := &sarama.ProducerMessage{
Topic: k.Topic,
Value: sarama.ByteEncoder(buf),
}
if h, ok := metric.Tags()[k.RoutingTag]; ok {
m.Key = sarama.StringEncoder(h)
}
if pubErr != nil {
return fmt.Errorf("FAILED to send kafka message: %s\n", pubErr)
_, _, err = k.producer.SendMessage(m)
if err != nil {
return fmt.Errorf("FAILED to send kafka message: %s\n", err)
}
}
return nil