Skip to content

Instantly share code, notes, and snippets.

@eapache
Created October 20, 2014 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eapache/ce0f15311c605a165ce7 to your computer and use it in GitHub Desktop.
Save eapache/ce0f15311c605a165ce7 to your computer and use it in GitHub Desktop.
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