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);
}
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");
}
};
}
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");
}
};
}
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));
}
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();
}
Aggregations