Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created November 30, 2018 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/9a11b73a4fa40574c0edbe8cfeb3a14a to your computer and use it in GitHub Desktop.
Save abhirockzz/9a11b73a4fa40574c0edbe8cfeb3a14a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/confluentinc/confluent-kafka-go/kafka"
)
func main() {
kafkaBroker := "foo:9092"
p, err := kafka.NewProducer(&kafka.ConfigMap{"bootstrap.servers": kafkaBroker})
if err != nil {
fmt.Println("producer creation failed ", err.Error())
return
}
topic := "bar"
partition := kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny}
msg := &kafka.Message{TopicPartition: partition, Key: []byte("hello"), Value: []byte("world")}
err = p.Produce(msg, nil)
fmt.Println("done...")
event := <-p.Events()
switch e := event.(type) {
case kafka.Error:
pErr := e
fmt.Println("producer error", pErr.String())
default:
fmt.Println("Kafka producer event", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment