Add support for Kafka record headers (#1025)

Added support for Kafka headers to be passed and retrieved from functions. The headers and supported and work only for Kafka version 0.11.0.0 and higher.
This commit is contained in:
Bhavin Gandhi
2019-01-12 21:16:13 +05:30
committed by Vishal
parent ad4c4cd014
commit 37f37c0b8b
7 changed files with 114 additions and 25 deletions
@@ -14,14 +14,18 @@ func Handler(w http.ResponseWriter, r *http.Request) {
producerConfig.Producer.RequiredAcks = sarama.WaitForAll
producerConfig.Producer.Retry.Max = 10
producerConfig.Producer.Return.Successes = true
producerConfig.Version = sarama.V0_11_0_0
producer, err := sarama.NewSyncProducer(brokers, producerConfig)
fmt.Println("Created a new producer ", producer)
if err != nil {
panic(err)
}
headers := []sarama.RecordHeader{{Key: []byte("Z-Custom-Name"), Value: []byte("Kafka-Header-test")}}
_, _, err = producer.SendMessage(&sarama.ProducerMessage{
Topic: "testtopic",
Value: sarama.StringEncoder("{\"name\": \"testvalue\"}"),
Topic: "testtopic",
Value: sarama.StringEncoder("{\"name\": \"testvalue\"}"),
Headers: headers,
})
if err != nil {