// 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 x copies of a message func SendManyMessages() { broker := kafka.NewBrokerPublisher(hostname, topic, partition) timing := kafka.StartTiming("Sending") fmt.Println("Publishing :", message, ": Will send ", sendCt, " times") done := make(chan bool) msgChan := make(chan *kafka.MessageTopic, 1000) go broker.PublishOnChannel(msgChan, 100, 100, done) for i := 0; i < sendCt; i++ { msgChan <- MakeMsg([]byte(message)) } done <- true // force flush timing.Print() }