diff --git a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java index 933c318849f7d..db2abbd6d4646 100644 --- a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java +++ b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java @@ -2,44 +2,37 @@ import java.util.HashMap; import java.util.Map; -import java.util.stream.StreamSupport; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.Dependent; import javax.enterprise.inject.Produces; import javax.inject.Named; +import javax.inject.Singleton; import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.ConfigProvider; import io.quarkus.arc.DefaultBean; -@Dependent +@Singleton public class KafkaRuntimeConfigProducer { - private String configPrefix = "kafka"; + private static final String CONFIG_PREFIX = "kafka"; @Produces @DefaultBean - @ApplicationScoped + @Singleton @Named("default-kafka-broker") - public Map createKafkaRuntimeConfig() { - Map properties = new HashMap<>(); - final Config config = ConfigProvider.getConfig(); - - StreamSupport - .stream(config.getPropertyNames().spliterator(), false) - .map(String::toLowerCase) - .filter(name -> name.startsWith(configPrefix)) - .distinct() - .sorted() - .forEach(name -> { - final String key = name.substring(configPrefix.length() + 1).toLowerCase().replaceAll("[^a-z0-9.]", "."); - final String value = config.getOptionalValue(name, String.class).orElse(""); - properties.put(key, value); - }); - - return properties; + public Map createKafkaRuntimeConfig(Config config) { + Map result = new HashMap<>(); + for (String propertyName : config.getPropertyNames()) { + String propertyNameLowerCase = propertyName.toLowerCase(); + if (!propertyNameLowerCase.startsWith(CONFIG_PREFIX)) { + continue; + } + String effectivePropertyName = propertyNameLowerCase.substring(CONFIG_PREFIX.length() + 1).toLowerCase() + .replaceAll("[^a-z0-9.]", "."); + String value = config.getOptionalValue(propertyName, String.class).orElse(""); + result.put(effectivePropertyName, value); + } + return result; } }