Skip to content

Instantly share code, notes, and snippets.

@amalakar
Created October 30, 2013 00:28
Show Gist options
  • Save amalakar/7225198 to your computer and use it in GitHub Desktop.
Save amalakar/7225198 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"sarama"
)
const (
topic = "aruptest"
)
func main() {
brokers := []string{"localhost:9092"}
clientId := "client"
client, err := sarama.NewClient(clientId, brokers, nil)
if err != nil {
panic("Unable to create kafka client " + err.Error())
}
producer, err := sarama.NewProducer(client, topic,
&sarama.ProducerConfig{
Partitioner: sarama.NewHashPartitioner(),
RequiredAcks: sarama.NoResponse,
Compression: sarama.CompressionGZIP}) // Snappy/Gzip compression is not working at the moment
if err != nil {
panic(fmt.Sprintf("Unable to create kafka producer: %v", err))
} else {
log.Printf("Successfully created kafka producer: %v. Topic: %v", brokers,
topic)
}
var msg string
for ;; {
fmt.Scanf("%s", &msg)
err = producer.SendMessage(nil, sarama.StringEncoder(msg))
if err == nil {
log.Printf("Request successfully sent: [%v]", msg)
} else {
log.Println("Request couldn't be sent: [%v]", msg)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment