Skip to content

Instantly share code, notes, and snippets.

@eapache
Created Oct 20, 2014
Embed
What would you like to do?
Kafka MessageSizeTooLarge Program
package main
import (
"fmt"
"log"
"os"
"github.com/Shopify/sarama"
)
func main() {
client, err := sarama.NewClient("client_id", []string{"localhost:9092"}, nil)
if err != nil {
panic(err)
} else {
fmt.Println("> connected")
}
defer client.Close()
sarama.Logger = log.New(os.Stdout, "[Sarama] ", log.LstdFlags)
producerConfig := sarama.NewProducerConfig()
producerConfig.Compression = sarama.CompressionSnappy
producer, err := sarama.NewProducer(client, producerConfig)
if err != nil {
panic(err)
}
defer producer.Close()
for {
select {
case producer.Input() <- &sarama.MessageToSend{Topic: "my_topic", Key: nil, Value: sarama.ByteEncoder(make([]byte, 1024))}:
case err := <-producer.Errors():
fmt.Println(err)
os.Exit(1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment