package main import ( "github.com/Shopify/sarama" "github.com/golang/glog" ) func main() { config := sarama.NewConfig() config.Producer.Return.Successes = true brokers := []string{"localhost:9092"} var err error producer, err := sarama.NewSyncProducer(brokers, config) if err != nil { glog.Errorf("Fail to create producer %v", err) } msg := &sarama.ProducerMessage{Topic: "send", Value: sarama.StringEncoder("test message for headers")} if msg.Headers == nil { msg.Headers = make([]sarama.RecordHeader, 1) } testHeader := sarama.RecordHeader{Key: []byte("testHeader1"), Value: []byte("testValue1")} msg.Headers = append(msg.Headers, testHeader) glog.Infof("producer message %v\n", msg) for _, header := range msg.Headers { if string(header.Key) != "" { glog.Infof("producer message header key %s, value %s\n", string(header.Key), string(header.Value)) } } producer.SendMessage(msg) }