kafka添加压缩配置后失败
添加压缩配置:
private Map<String, Object> producerConfigs() {Map<String, Object> props = new HashMap<>(NUM_16);props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);props.put(ProducerConfig.RETRIES_CONFIG, retries);props.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, retryBackoffMs);props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);// 开启gzip压缩props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, CompressionType.GZIP.name());return props;}报错:
Failed to construct kafka producer
原因:
CompressionType.GZIP.name() 结果是 GZIP
应该改成 CompressionType.GZIP.name,这个结果是gzip
name() 方法是枚举类Enum.java里的,取的是Enum的name属性
.name取的是CompressionType的name属性
