|
@@ -1,7 +1,10 @@
|
|
|
package sarama
|
|
package sarama
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "compress/gzip"
|
|
|
"crypto/tls"
|
|
"crypto/tls"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "io/ioutil"
|
|
|
"regexp"
|
|
"regexp"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
@@ -99,6 +102,10 @@ type Config struct {
|
|
|
// The type of compression to use on messages (defaults to no compression).
|
|
// The type of compression to use on messages (defaults to no compression).
|
|
|
// Similar to `compression.codec` setting of the JVM producer.
|
|
// Similar to `compression.codec` setting of the JVM producer.
|
|
|
Compression CompressionCodec
|
|
Compression CompressionCodec
|
|
|
|
|
+ // The level of compression to use on messages. The meaning depends
|
|
|
|
|
+ // on the actual compression type used and defaults to default compression
|
|
|
|
|
+ // level for the codec.
|
|
|
|
|
+ CompressionLevel int
|
|
|
// Generates partitioners for choosing the partition to send messages to
|
|
// Generates partitioners for choosing the partition to send messages to
|
|
|
// (defaults to hashing the message key). Similar to the `partitioner.class`
|
|
// (defaults to hashing the message key). Similar to the `partitioner.class`
|
|
|
// setting for the JVM producer.
|
|
// setting for the JVM producer.
|
|
@@ -290,6 +297,7 @@ func NewConfig() *Config {
|
|
|
c.Producer.Retry.Max = 3
|
|
c.Producer.Retry.Max = 3
|
|
|
c.Producer.Retry.Backoff = 100 * time.Millisecond
|
|
c.Producer.Retry.Backoff = 100 * time.Millisecond
|
|
|
c.Producer.Return.Errors = true
|
|
c.Producer.Return.Errors = true
|
|
|
|
|
+ c.Producer.CompressionLevel = CompressionLevelDefault
|
|
|
|
|
|
|
|
c.Consumer.Fetch.Min = 1
|
|
c.Consumer.Fetch.Min = 1
|
|
|
c.Consumer.Fetch.Default = 1024 * 1024
|
|
c.Consumer.Fetch.Default = 1024 * 1024
|
|
@@ -409,6 +417,14 @@ func (c *Config) Validate() error {
|
|
|
return ConfigurationError("lz4 compression requires Version >= V0_10_0_0")
|
|
return ConfigurationError("lz4 compression requires Version >= V0_10_0_0")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if c.Producer.Compression == CompressionGZIP {
|
|
|
|
|
+ if c.Producer.CompressionLevel != CompressionLevelDefault {
|
|
|
|
|
+ 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
|
|
// validate the Consumer values
|
|
|
switch {
|
|
switch {
|
|
|
case c.Consumer.Fetch.Min <= 0:
|
|
case c.Consumer.Fetch.Min <= 0:
|