Search in sources :

Example 6 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testServiceDiscoveryConfiguration.

@Test
public void testServiceDiscoveryConfiguration() {
    SpringCamelContext context = createContext("org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml");
    ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1");
    assertNotNull("No ServiceCallConfiguration (1)", conf1);
    assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration());
    assertNotNull("No ServiceCallLoadBalancerConfiguration (1)", conf1.getLoadBalancerConfiguration());
    assertTrue(conf1.getLoadBalancerConfiguration() instanceof DefaultServiceCallLoadBalancerConfiguration);
    StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration) conf1.getServiceDiscoveryConfiguration();
    assertEquals(1, discovery1.getServers().size());
    assertEquals("localhost:9091", discovery1.getServers().get(0));
    ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2");
    assertNotNull("No ServiceCallConfiguration (2)", conf2);
    assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
    assertNull(conf2.getLoadBalancerConfiguration());
    ChainedServiceCallServiceDiscoveryConfiguration discovery2 = (ChainedServiceCallServiceDiscoveryConfiguration) conf2.getServiceDiscoveryConfiguration();
    assertEquals(2, discovery2.getServiceDiscoveryConfigurations().size());
    assertTrue(discovery2.getServiceDiscoveryConfigurations().get(0) instanceof StaticServiceCallServiceDiscoveryConfiguration);
    assertTrue(discovery2.getServiceDiscoveryConfigurations().get(1) instanceof StaticServiceCallServiceDiscoveryConfiguration);
    StaticServiceCallServiceDiscoveryConfiguration sconf1 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(0);
    assertEquals(1, sconf1.getServers().size());
    assertEquals("localhost:9092", sconf1.getServers().get(0));
    StaticServiceCallServiceDiscoveryConfiguration sconf2 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(1);
    assertEquals(1, sconf2.getServers().size());
    assertEquals("localhost:9093,localhost:9094,localhost:9095,localhost:9096", sconf2.getServers().get(0));
    ChainedServiceCallServiceFilterConfiguration filter = (ChainedServiceCallServiceFilterConfiguration) conf2.getServiceFilterConfiguration();
    assertEquals(2, filter.getServiceFilterConfigurations().size());
    assertTrue(filter.getServiceFilterConfigurations().get(0) instanceof HealthyServiceCallServiceFilterConfiguration);
    assertTrue(filter.getServiceFilterConfigurations().get(1) instanceof BlacklistServiceCallServiceFilterConfiguration);
}
Also used : DefaultServiceCallLoadBalancerConfiguration(org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration) ChainedServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) BlacklistServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration) HealthyServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) StaticServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration) ChainedServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration) Test(org.junit.Test)

Example 7 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition 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 8 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallEnvironmentRouteTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            KubernetesConfiguration kubernetesConfiguration = new KubernetesConfiguration();
            ServiceCallConfigurationDefinition config = new ServiceCallConfigurationDefinition();
            config.setServiceDiscovery(new KubernetesEnvServiceDiscovery(kubernetesConfiguration));
            // register configuration
            context.setServiceCallConfiguration(config);
            from("direct:start").serviceCall("cdi-camel-jetty").serviceCall("cdi-camel-jetty").to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) KubernetesConfiguration(org.apache.camel.component.kubernetes.KubernetesConfiguration) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)

Example 9 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class XmlServiceCallConfigurationTest method testServiceDiscoveryConfiguration.

@Test
public void testServiceDiscoveryConfiguration() {
    ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1");
    assertNotNull("No ServiceCallConfiguration (1)", conf1);
    assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration());
    StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration) conf1.getServiceDiscoveryConfiguration();
    assertEquals(1, discovery1.getServers().size());
    assertEquals("localhost:9091", discovery1.getServers().get(0));
    ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2");
    assertNotNull("No ServiceCallConfiguration (2)", conf2);
    assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
    StaticServiceCallServiceDiscoveryConfiguration discovery2 = (StaticServiceCallServiceDiscoveryConfiguration) conf2.getServiceDiscoveryConfiguration();
    assertEquals(2, discovery2.getServers().size());
    assertEquals("localhost:9092", discovery2.getServers().get(0));
    assertEquals("localhost:9093,localhost:9094", discovery2.getServers().get(1));
}
Also used : ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) StaticServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration) Test(org.junit.Test)

Example 10 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testDefaultConfigurationFromRegistryWithNonDefaultName.

@Test
public void testDefaultConfigurationFromRegistryWithNonDefaultName() throws Exception {
    StaticServiceDiscovery sd = new StaticServiceDiscovery();
    sd.addServer("127.0.0.1:8080");
    sd.addServer("127.0.0.1:8081");
    BlacklistServiceFilter sf = new BlacklistServiceFilter();
    sf.addServer("127.0.0.1:8080");
    ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
    conf.setServiceDiscovery(sd);
    conf.serviceFilter(sf);
    SimpleRegistry reg = new SimpleRegistry();
    reg.put(UUID.randomUUID().toString(), conf);
    CamelContext context = new DefaultCamelContext(reg);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("default").serviceCall().name("scall").component("file").end();
        }
    });
    context.start();
    DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
    Assert.assertNotNull(proc);
    Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
    DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
    Assert.assertEquals(sd, loadBalancer.getServiceDiscovery());
    Assert.assertEquals(sf, loadBalancer.getServiceFilter());
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

ServiceCallConfigurationDefinition (org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 Test (org.junit.Test)7 CamelContext (org.apache.camel.CamelContext)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 StaticServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration)3 KubernetesConfiguration (org.apache.camel.component.kubernetes.KubernetesConfiguration)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 RibbonConfiguration (org.apache.camel.component.ribbon.RibbonConfiguration)1 StaticServiceDiscovery (org.apache.camel.impl.cloud.StaticServiceDiscovery)1 BlacklistServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration)1 ChainedServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration)1 ChainedServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration)1 DefaultServiceCallLoadBalancerConfiguration (org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration)1 HealthyServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1