confluent-kafka-go
confluent-kafka-go copied to clipboard
Producer:what's the event type of event delivered by delivery_chan
Description
delivery_chan := make(chan kafka.Event, 10000)
err = p.Produce(&kafka.Message{
TopicPartition: kafka.TopicPartition{Topic: topic, Partition: kafka.PartitionAny},
Value: []byte(value)},
delivery_chan
)
e := <-delivery_chan
m := e.(*kafka.Message)
if m.TopicPartition.Error != nil {
fmt.Printf("Delivery failed: %v\n", m.TopicPartition.Error)
} else {
fmt.Printf("Delivered message to topic %s [%d] at offset %v\n",
*m.TopicPartition.Topic, m.TopicPartition.Partition, m.TopicPartition.Offset)
}
close(delivery_chan)
for this simple example, copy from confluent official site will this line m := e.(*kafka.Message)
panic ?, because e is another type.
Should I write a for loop to wait for an event whose type is *kafka.Message
for e := range delivery_chan{
// do type switch, if type is *kafka.Message , log error if any and return
}