Skip to main content
Version: 3.x

Compression

In this section, we will learn how to configure Producer Compression in KafkaFlow.

KafkaFlow relies on the native message compression provided by the Confluent Kafka client.

The following compression types are supported:

  • Gzip
  • Snappy
  • Lz4
  • Zstd
.WithCompression(CompressionType.Gzip)
info

If you want to use a different compression type, visit the Compressor Middleware guide.

Optionally, it's possible to specify the compression level, providing it as the second argument. You can find the possible values here.

.WithCompression(CompressionType.Gzip, 5)
info

The configuration must be done only by the producers. The consumers will identify compressed messages and decompress them automatically.

services.AddKafka(kafka => kafka
.AddCluster(cluster => cluster
.WithBrokers(new[] { "localhost:9092" })
.AddProducer<ProductEventsProducer>(producer => producer
.WithCompression(CompressionType.Gzip)
...
)
)
)
);