From 2c3c2f7065915048417ba13dda304d56107dbe54 Mon Sep 17 00:00:00 2001 From: Lars Krog-Jensen Date: Wed, 6 Jan 2021 11:20:19 +0100 Subject: [PATCH] Remove kcache specific properties before delegating to underlying kafka consumer and producers to avoid warnings --- kcache/src/main/java/io/kcache/KafkaCache.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kcache/src/main/java/io/kcache/KafkaCache.java b/kcache/src/main/java/io/kcache/KafkaCache.java index ade9008b..985eece7 100644 --- a/kcache/src/main/java/io/kcache/KafkaCache.java +++ b/kcache/src/main/java/io/kcache/KafkaCache.java @@ -20,9 +20,8 @@ import io.kcache.exceptions.CacheInitializationException; import io.kcache.exceptions.CacheTimeoutException; import io.kcache.utils.InMemoryCache; -import io.kcache.utils.ShutdownableThread; import io.kcache.utils.OffsetCheckpoint; -import java.lang.reflect.Constructor; +import io.kcache.utils.ShutdownableThread; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.AdminClientConfig; import org.apache.kafka.clients.admin.Config; @@ -55,6 +54,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.lang.reflect.Constructor; import java.time.Duration; import java.util.Collection; import java.util.Collections; @@ -289,7 +289,15 @@ private Producer createProducer() { } private void addKafkaCacheConfigsToClientProperties(Properties props) { - props.putAll(config.originalsWithPrefix("kafkacache.")); + // remove kcache used properties before passing on to delegated consumer and producer + // to avoid warnings + // thus unused props are those that kcache should propagate + + Map unusedProps = config.originals().entrySet().stream() + .filter(kv -> config.unused().contains(kv.getKey())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + KafkaCacheConfig vettedConfig = new KafkaCacheConfig(unusedProps); + props.putAll(vettedConfig.originalsWithPrefix("kafkacache.")); } private void createOrVerifyTopic() throws CacheInitializationException {