Created
October 4, 2016 14:13
-
-
Save niels-s/2381bca40d006fbf75c1e2cbfddfdbbc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"log" | |
"os" | |
"time" | |
"github.com/Shopify/sarama" | |
) | |
func main() { | |
config := sarama.NewConfig() | |
config.Version = sarama.V0_10_0_0 | |
config.Producer.Return.Errors = true | |
config.Producer.Retry.Max = 10 | |
config.Producer.Compression = sarama.CompressionSnappy // or GZIP don't work in combination with Timestamp! | |
config.Producer.Flush.Frequency = 500 * time.Millisecond | |
config.ClientID = "test" | |
sarama.Logger = log.New(os.Stdout, "[sarama] ", log.LstdFlags) | |
producer, err := sarama.NewAsyncProducer([]string{"localhost:9092"}, config) | |
if err != nil { | |
log.Fatalln("[ERROR] Failed to start Sarama producer:", err) | |
} | |
defer producer.Close() | |
go func() { | |
for err := range producer.Errors() { | |
log.Printf("[ERROR]: %s\n", err.Error()) | |
} | |
}() | |
producer.Input() <- &sarama.ProducerMessage{ | |
Timestamp: time.Now(), | |
Topic: "bla", | |
Value: sarama.ByteEncoder("test this message"), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment