// sends file & exits func SendFile(msgFile string) { broker := kafka.NewBrokerPublisher(hostname, topic, partition) fmt.Println("Publishing File:", msgFile) file, err := os.Open(msgFile) if err != nil { fmt.Println("Error: ", err) return } stat, err := file.Stat() if err != nil { fmt.Println("Error: ", err) return } payload := make([]byte, stat.Size()) file.Read(payload) timing := kafka.StartTiming("Sending") if compress { broker.Publish(kafka.NewCompressedMessage(payload)) } else { broker.Publish(kafka.NewMessage(payload)) } timing.Print() file.Close() }
// sends single message and exits func SendMessage() { broker := kafka.NewBrokerPublisher(hostname, topic, partition) fmt.Println("Publishing :", message) broker.Publish(kafka.NewMessage([]byte(message))) }