diff --git a/config.go b/config.go index 36263d8833..68dc7abb43 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,10 @@ package sarama import ( + "compress/gzip" "crypto/tls" + "fmt" + "io/ioutil" "regexp" "time" @@ -414,6 +417,12 @@ func (c *Config) Validate() error { return ConfigurationError("lz4 compression requires Version >= V0_10_0_0") } + if c.Producer.Compression == CompressionGZIP { + if _, err := gzip.NewWriterLevel(ioutil.Discard, c.Producer.CompressionLevel); err != nil { + return ConfigurationError(fmt.Sprintf("gzip compression does not work with level %d: %v", c.Producer.CompressionLevel, err)) + } + } + // validate the Consumer values switch { case c.Consumer.Fetch.Min <= 0: