Search in sources :

Example 1 with HealthyServiceFilter

use of org.apache.camel.impl.cloud.HealthyServiceFilter in project camel by apache.

the class ServiceCallDefinition method retrieveServiceFilter.

// ******************************************
// ServiceFilter
// ******************************************
private ServiceFilter retrieveServiceFilter(CamelContext camelContext, Function<CamelContext, ServiceCallConfigurationDefinition> function) throws Exception {
    ServiceFilter answer = null;
    ServiceCallConfigurationDefinition config = function.apply(camelContext);
    if (config != null) {
        if (config.getServiceFilterConfiguration() != null) {
            answer = config.getServiceFilterConfiguration().newInstance(camelContext);
        } else {
            answer = retrieve(ServiceFilter.class, camelContext, config::getServiceFilter, config::getServiceFilterRef);
        }
        if (answer == null) {
            String ref = config.getServiceFilterRef();
            if (ObjectHelper.equal("healthy", ref, true)) {
                answer = new HealthyServiceFilter();
            } else if (ObjectHelper.equal("pass-through", ref, true)) {
                answer = new PassThroughServiceFilter();
            } else if (ObjectHelper.equal("passthrough", ref, true)) {
                answer = new PassThroughServiceFilter();
            }
        }
    }
    return answer;
}
Also used : PassThroughServiceFilter(org.apache.camel.impl.cloud.PassThroughServiceFilter) ServiceFilter(org.apache.camel.cloud.ServiceFilter) HealthyServiceFilter(org.apache.camel.impl.cloud.HealthyServiceFilter) PassThroughServiceFilter(org.apache.camel.impl.cloud.PassThroughServiceFilter) HealthyServiceFilter(org.apache.camel.impl.cloud.HealthyServiceFilter)

Example 2 with HealthyServiceFilter

use of org.apache.camel.impl.cloud.HealthyServiceFilter in project camel by apache.

the class CamelCloudServiceFilterAutoConfiguration method serviceFilter.

@Lazy
@Bean(name = "service-filter")
public CamelCloudServiceFilter serviceFilter(CamelCloudConfigurationProperties properties) {
    BlacklistServiceFilter blacklist = new BlacklistServiceFilter();
    Map<String, List<String>> services = properties.getServiceFilter().getBlacklist();
    for (Map.Entry<String, List<String>> entry : services.entrySet()) {
        for (String part : entry.getValue()) {
            String host = StringHelper.before(part, ":");
            String port = StringHelper.after(part, ":");
            if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
                blacklist.addServer(entry.getKey(), host, Integer.parseInt(port));
            }
        }
    }
    return new CamelCloudServiceFilter(Arrays.asList(new HealthyServiceFilter(), blacklist));
}
Also used : HealthyServiceFilter(org.apache.camel.impl.cloud.HealthyServiceFilter) List(java.util.List) BlacklistServiceFilter(org.apache.camel.impl.cloud.BlacklistServiceFilter) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean)

Aggregations

HealthyServiceFilter (org.apache.camel.impl.cloud.HealthyServiceFilter)2 List (java.util.List)1 Map (java.util.Map)1 ServiceFilter (org.apache.camel.cloud.ServiceFilter)1 BlacklistServiceFilter (org.apache.camel.impl.cloud.BlacklistServiceFilter)1 PassThroughServiceFilter (org.apache.camel.impl.cloud.PassThroughServiceFilter)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1