如何设置 Kafka Streams 消息压缩?

How to Setup Kafka Streams Message Compression?

使用 Kafka Streams,我们无法确定在处理完写入接收器主题的消息后压缩消息所需的配置。

另一方面,使用经典的 Kafka Producer,通过在 KafkaProducer properties

上设置配置 "compression.type" 可以轻松实现压缩

但是,似乎没有任何记录在案的示例让 Kafka Streams 压缩已处理的消息。

至于这次(2019 年初),有没有办法使用 Kafka Streams 进行压缩?

内部使用的producer可以在StreamConfig中指定参数,如下图:

final Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "your-streams-app-id");
props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "lz4");

输出主题将使用 LZ4 算法进行压缩。

有关详细信息,请参阅 https://docs.confluent.io/current/streams/developer-guide/config-streams.html#kafka-consumers-producer-and-admin-client-configuration-parameters