Search in sources :

Example 1 with BinderConfiguration

use of org.springframework.cloud.stream.binder.BinderConfiguration in project spring-cloud-stream by spring-cloud.

the class BinderFactoryConfiguration method getBinderConfigurations.

private Map<String, BinderConfiguration> getBinderConfigurations(BinderTypeRegistry binderTypeRegistry, BindingServiceProperties bindingServiceProperties) {
    Map<String, BinderConfiguration> binderConfigurations = new HashMap<>();
    Map<String, BinderProperties> declaredBinders = bindingServiceProperties.getBinders();
    boolean defaultCandidatesExist = false;
    Iterator<Map.Entry<String, BinderProperties>> binderPropertiesIterator = declaredBinders.entrySet().iterator();
    while (!defaultCandidatesExist && binderPropertiesIterator.hasNext()) {
        defaultCandidatesExist = binderPropertiesIterator.next().getValue().isDefaultCandidate();
    }
    List<String> existingBinderConfigurations = new ArrayList<>();
    for (Map.Entry<String, BinderProperties> binderEntry : declaredBinders.entrySet()) {
        BinderProperties binderProperties = binderEntry.getValue();
        if (binderTypeRegistry.get(binderEntry.getKey()) != null) {
            binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderEntry.getKey(), binderProperties.getEnvironment(), binderProperties.isInheritEnvironment(), binderProperties.isDefaultCandidate()));
            existingBinderConfigurations.add(binderEntry.getKey());
        } else {
            Assert.hasText(binderProperties.getType(), "No 'type' property present for custom binder " + binderEntry.getKey());
            binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderProperties.getType(), binderProperties.getEnvironment(), binderProperties.isInheritEnvironment(), binderProperties.isDefaultCandidate()));
            existingBinderConfigurations.add(binderEntry.getKey());
        }
    }
    for (Map.Entry<String, BinderConfiguration> configurationEntry : binderConfigurations.entrySet()) {
        if (configurationEntry.getValue().isDefaultCandidate()) {
            defaultCandidatesExist = true;
        }
    }
    if (!defaultCandidatesExist) {
        for (Map.Entry<String, BinderType> binderEntry : binderTypeRegistry.getAll().entrySet()) {
            if (!existingBinderConfigurations.contains(binderEntry.getKey())) {
                binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderEntry.getKey(), new HashMap<>(), true, true));
            }
        }
    }
    return binderConfigurations;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BinderConfiguration(org.springframework.cloud.stream.binder.BinderConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) BinderType(org.springframework.cloud.stream.binder.BinderType)

Example 2 with BinderConfiguration

use of org.springframework.cloud.stream.binder.BinderConfiguration in project spring-cloud-stream by spring-cloud.

the class BindingServiceConfiguration method getBinderConfigurations.

private static Map<String, BinderConfiguration> getBinderConfigurations(BinderTypeRegistry binderTypeRegistry, BindingServiceProperties bindingServiceProperties) {
    Map<String, BinderConfiguration> binderConfigurations = new HashMap<>();
    Map<String, BinderProperties> declaredBinders = bindingServiceProperties.getBinders();
    boolean defaultCandidatesExist = false;
    Iterator<Map.Entry<String, BinderProperties>> binderPropertiesIterator = declaredBinders.entrySet().iterator();
    while (!defaultCandidatesExist && binderPropertiesIterator.hasNext()) {
        defaultCandidatesExist = binderPropertiesIterator.next().getValue().isDefaultCandidate();
    }
    List<String> existingBinderConfigurations = new ArrayList<>();
    for (Map.Entry<String, BinderProperties> binderEntry : declaredBinders.entrySet()) {
        BinderProperties binderProperties = binderEntry.getValue();
        if (binderTypeRegistry.get(binderEntry.getKey()) != null) {
            binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderEntry.getKey(), binderProperties.getEnvironment(), binderProperties.isInheritEnvironment(), binderProperties.isDefaultCandidate()));
            existingBinderConfigurations.add(binderEntry.getKey());
        } else {
            Assert.hasText(binderProperties.getType(), "No 'type' property present for custom binder " + binderEntry.getKey());
            binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderProperties.getType(), binderProperties.getEnvironment(), binderProperties.isInheritEnvironment(), binderProperties.isDefaultCandidate()));
            existingBinderConfigurations.add(binderEntry.getKey());
        }
    }
    for (Map.Entry<String, BinderConfiguration> configurationEntry : binderConfigurations.entrySet()) {
        if (configurationEntry.getValue().isDefaultCandidate()) {
            defaultCandidatesExist = true;
        }
    }
    if (!defaultCandidatesExist) {
        for (Map.Entry<String, BinderType> binderEntry : binderTypeRegistry.getAll().entrySet()) {
            if (!existingBinderConfigurations.contains(binderEntry.getKey())) {
                binderConfigurations.put(binderEntry.getKey(), new BinderConfiguration(binderEntry.getKey(), new HashMap<>(), true, !"integration".equals(binderEntry.getKey())));
            }
        }
    }
    return binderConfigurations;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BinderConfiguration(org.springframework.cloud.stream.binder.BinderConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) BinderType(org.springframework.cloud.stream.binder.BinderType)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BinderConfiguration (org.springframework.cloud.stream.binder.BinderConfiguration)2 BinderType (org.springframework.cloud.stream.binder.BinderType)2