Search in sources :

Example 1 with StaticServiceDiscovery

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

the class RibbonServiceCallRegistryRouteTest method createRouteBuilder.

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // setup a static ribbon server list with these 2 servers to start with
            StaticServiceDiscovery servers = new StaticServiceDiscovery();
            servers.addServer("localhost", 9090);
            servers.addServer("localhost", 9091);
            RibbonConfiguration configuration = new RibbonConfiguration();
            RibbonLoadBalancer loadBalancer = new RibbonLoadBalancer(configuration);
            // configure camel service call
            ServiceCallConfigurationDefinition config = new ServiceCallConfigurationDefinition();
            config.setLoadBalancer(loadBalancer);
            config.setServiceDiscovery(servers);
            // register configuration
            context.setServiceCallConfiguration(config);
            from("direct:start").serviceCall("myService").to("mock:result");
            from("jetty:http://localhost:9090").to("mock:9090").transform().constant("9090");
            from("jetty:http://localhost:9091").to("mock:9091").transform().constant("9091");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) StaticServiceDiscovery(org.apache.camel.impl.cloud.StaticServiceDiscovery) RibbonConfiguration(org.apache.camel.component.ribbon.RibbonConfiguration) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)

Example 2 with StaticServiceDiscovery

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

the class RibbonServiceCallRouteTest method createRouteBuilder.

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // setup a static ribbon server list with these 2 servers to start with
            StaticServiceDiscovery servers = new StaticServiceDiscovery();
            servers.addServer("localhost", 9090);
            servers.addServer("localhost", 9091);
            RibbonConfiguration configuration = new RibbonConfiguration();
            RibbonLoadBalancer loadBalancer = new RibbonLoadBalancer(configuration);
            from("direct:start").serviceCall().name("myService").loadBalancer(loadBalancer).serviceDiscovery(servers).end().to("mock:result");
            from("jetty:http://localhost:9090").to("mock:9090").transform().constant("9090");
            from("jetty:http://localhost:9091").to("mock:9091").transform().constant("9091");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) StaticServiceDiscovery(org.apache.camel.impl.cloud.StaticServiceDiscovery) RibbonConfiguration(org.apache.camel.component.ribbon.RibbonConfiguration)

Example 3 with StaticServiceDiscovery

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

the class CamelCloudServiceDiscoveryAutoConfiguration method staticServiceDiscovery.

@Lazy
@Bean(name = "static-service-discovery")
public ServiceDiscovery staticServiceDiscovery(CamelCloudConfigurationProperties properties) {
    StaticServiceDiscovery staticServiceDiscovery = new StaticServiceDiscovery();
    Map<String, List<String>> services = properties.getServiceDiscovery().getServices();
    for (Map.Entry<String, List<String>> entry : services.entrySet()) {
        staticServiceDiscovery.addServers(entry.getKey(), entry.getValue());
    }
    return staticServiceDiscovery;
}
Also used : StaticServiceDiscovery(org.apache.camel.impl.cloud.StaticServiceDiscovery) List(java.util.List) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean)

Aggregations

StaticServiceDiscovery (org.apache.camel.impl.cloud.StaticServiceDiscovery)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 RibbonConfiguration (org.apache.camel.component.ribbon.RibbonConfiguration)2 List (java.util.List)1 Map (java.util.Map)1 ServiceCallConfigurationDefinition (org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1