Search in sources :

Example 1 with Environment

use of io.micronaut.context.env.Environment in project micronaut-kafka by micronaut-projects.

the class KafkaDefaultConfiguration method resolveDefaultConfiguration.

private static Properties resolveDefaultConfiguration(Environment environment) {
    Map<String, Object> values = environment.containsProperties(PREFIX) ? environment.getProperties(PREFIX) : Collections.emptyMap();
    Properties properties = new Properties();
    values.entrySet().stream().filter(entry -> {
        String key = entry.getKey();
        return Stream.of("embedded", "consumers", "producers", "streams").noneMatch(key::startsWith);
    }).forEach(entry -> {
        Object value = entry.getValue();
        if (ConversionService.SHARED.canConvert(entry.getValue().getClass(), String.class)) {
            Optional<?> converted = ConversionService.SHARED.convert(entry.getValue(), String.class);
            if (converted.isPresent()) {
                value = converted.get();
            }
        }
        properties.setProperty(entry.getKey(), value.toString());
    });
    return properties;
}
Also used : Environment(io.micronaut.context.env.Environment) StringUtils(io.micronaut.core.util.StringUtils) Properties(java.util.Properties) Stream(java.util.stream.Stream) ConfigurationProperties(io.micronaut.context.annotation.ConfigurationProperties) Duration(java.time.Duration) Map(java.util.Map) Requires(io.micronaut.context.annotation.Requires) Optional(java.util.Optional) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) ConversionService(io.micronaut.core.convert.ConversionService) Collections(java.util.Collections) Properties(java.util.Properties) ConfigurationProperties(io.micronaut.context.annotation.ConfigurationProperties)

Aggregations

ConfigurationProperties (io.micronaut.context.annotation.ConfigurationProperties)1 Requires (io.micronaut.context.annotation.Requires)1 Environment (io.micronaut.context.env.Environment)1 ConversionService (io.micronaut.core.convert.ConversionService)1 StringUtils (io.micronaut.core.util.StringUtils)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Stream (java.util.stream.Stream)1 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)1