Created
November 30, 2018 09:20
-
-
Save abhirockzz/9a11b73a4fa40574c0edbe8cfeb3a14a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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