http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.java new file mode 100644 index 0000000..34269b3 --- /dev/null +++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.ribbon.cloud; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.test.annotation.DirtiesContext; + +@DirtiesContext +public class SpringDslRibbonServiceCallRouteTest extends SpringRibbonServiceCallRouteTest { + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.xml"); + } +} +
http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringRibbonServiceCallRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringRibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringRibbonServiceCallRouteTest.java new file mode 100644 index 0000000..3c9e8b2 --- /dev/null +++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/SpringRibbonServiceCallRouteTest.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.ribbon.cloud; + +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.test.annotation.DirtiesContext; + +@DirtiesContext +public abstract class SpringRibbonServiceCallRouteTest extends CamelSpringTestSupport { + @Test + public void testServiceCall() throws Exception { + getMockEndpoint("mock:9090").expectedMessageCount(1); + getMockEndpoint("mock:9091").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedMessageCount(2); + + String out = template.requestBody("direct:start", null, String.class); + String out2 = template.requestBody("direct:start", null, String.class); + assertEquals("9091", out); + assertEquals("9090", out2); + + assertMockEndpointsSatisfied(); + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServerListTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServerListTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServerListTest.java deleted file mode 100644 index 4671709..0000000 --- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServerListTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ribbon.processor; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import com.netflix.loadbalancer.LoadBalancerBuilder; -import com.netflix.loadbalancer.RoundRobinRule; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerList; -import com.netflix.loadbalancer.ZoneAwareLoadBalancer; -import org.junit.Test; - -public class RibbonServerListTest extends TestCase { - - @Test - public void testFixedServerList() throws Exception { - List<RibbonServer> servers = new ArrayList<>(); - servers.add(new RibbonServer("localhost", 9090)); - servers.add(new RibbonServer("localhost", 9091)); - - ServerList<RibbonServer> list = new RibbonServiceCallStaticServerListStrategy(servers); - - ZoneAwareLoadBalancer<RibbonServer> lb = LoadBalancerBuilder.<RibbonServer>newBuilder() - .withDynamicServerList(list) - .withRule(new RoundRobinRule()).buildDynamicServerListLoadBalancer(); - - Server server = lb.chooseServer(); - assertEquals("localhost", server.getHost()); - assertEquals(9091, server.getPort()); - - server = lb.chooseServer(); - assertEquals("localhost", server.getHost()); - assertEquals(9090, server.getPort()); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRegistryRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRegistryRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRegistryRouteTest.java deleted file mode 100644 index b1c7d4d..0000000 --- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRegistryRouteTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ribbon.processor; - -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.model.remote.RibbonConfigurationDefinition; - -public class RibbonServiceCallRegistryRouteTest extends RibbonServiceCallRouteTest { - - @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 - RibbonServiceCallStaticServerListStrategy servers = new RibbonServiceCallStaticServerListStrategy(); - servers.addServer("localhost", 9090); - servers.addServer("localhost", 9091); - - // configure camel service call - RibbonConfigurationDefinition config = new RibbonConfigurationDefinition(); - config.setServerListStrategy(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"); - } - }; - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRouteTest.java deleted file mode 100644 index a3abc29..0000000 --- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallRouteTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ribbon.processor; - -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class RibbonServiceCallRouteTest extends CamelTestSupport { - - @Test - public void testServiceCall() throws Exception { - getMockEndpoint("mock:9090").expectedMessageCount(1); - getMockEndpoint("mock:9091").expectedMessageCount(1); - getMockEndpoint("mock:result").expectedMessageCount(2); - - String out = template.requestBody("direct:start", null, String.class); - String out2 = template.requestBody("direct:start", null, String.class); - assertEquals("9091", out); - assertEquals("9090", out2); - - assertMockEndpointsSatisfied(); - } - - @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 - RibbonServiceCallStaticServerListStrategy servers = new RibbonServiceCallStaticServerListStrategy(); - servers.addServer("localhost", 9090); - servers.addServer("localhost", 9091); - - from("direct:start") - .serviceCall().name("myService").ribbonConfiguration().serverListStrategy(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"); - } - }; - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallUpdateRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallUpdateRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallUpdateRouteTest.java deleted file mode 100644 index a37f5bc..0000000 --- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallUpdateRouteTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ribbon.processor; - -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class RibbonServiceCallUpdateRouteTest extends CamelTestSupport { - - private final RibbonServiceCallStaticServerListStrategy servers = new RibbonServiceCallStaticServerListStrategy(); - - @Override - public void setUp() throws Exception { - // setup a static ribbon server list with these 2 servers to start with - servers.addServer("localhost", 9090); - servers.addServer("localhost", 9091); - - super.setUp(); - } - - @Test - public void testServiceCall() throws Exception { - getMockEndpoint("mock:9090").expectedMessageCount(1); - getMockEndpoint("mock:9091").expectedMessageCount(1); - getMockEndpoint("mock:result").expectedMessageCount(2); - - String out = template.requestBody("direct:start", null, String.class); - String out2 = template.requestBody("direct:start", null, String.class); - assertEquals("9091", out); - assertEquals("9090", out2); - - assertMockEndpointsSatisfied(); - - // stop the first server and remove it from the known list of servers - context.stopRoute("9090"); - servers.removeServer("localhost", 9090); - - // call the other active server - String out3 = template.requestBody("direct:start", null, String.class); - assertEquals("9091", out3); - - // sleep a bit to make the server updated run and detect that a server is no longer in the list - log.debug("Sleeping to all the server list updated to run"); - Thread.sleep(1000); - log.debug("Calling the service now"); - - // call again and it should call 9091 as its the only active server - String out4 = template.requestBody("direct:start", null, String.class); - assertEquals("9091", out4); - } - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start") - .serviceCall().name("myService") - // lets update quick so we do not have to sleep so much in the tests - .ribbonConfiguration().serverListStrategy(servers).clientProperty("ServerListRefreshInterval", "250").end() - .to("mock:result"); - - from("jetty:http://localhost:9090").routeId("9090") - .to("mock:9090") - .transform().constant("9090"); - - from("jetty:http://localhost:9091").routeId("9091") - .to("mock:9091") - .transform().constant("9091"); - } - }; - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java deleted file mode 100644 index 6b35b75..0000000 --- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ribbon.processor; - -import org.apache.camel.test.spring.CamelSpringTestSupport; -import org.junit.Test; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class SpringRibbonServiceCallRouteTest extends CamelSpringTestSupport { - - @Override - protected AbstractApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml"); - } - - @Test - public void testServiceCall() throws Exception { - getMockEndpoint("mock:9090").expectedMessageCount(1); - getMockEndpoint("mock:9091").expectedMessageCount(1); - getMockEndpoint("mock:result").expectedMessageCount(2); - - String out = template.requestBody("direct:start", null, String.class); - String out2 = template.requestBody("direct:start", null, String.class); - assertEquals("9091", out); - assertEquals("9090", out2); - - assertMockEndpointsSatisfied(); - } - -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringBeanRibbonServiceCallRouteTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringBeanRibbonServiceCallRouteTest.xml b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringBeanRibbonServiceCallRouteTest.xml new file mode 100644 index 0000000..01e59d9 --- /dev/null +++ b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringBeanRibbonServiceCallRouteTest.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring + http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <!-- setup a static ribbon server list with these 2 servers to start with --> + <bean id="discovery" class="org.apache.camel.impl.cloud.StaticServiceDiscovery"> + <property name="servers" value="localhost:9090,localhost:9091"/> + </bean> + + <bean id="balancer" class="org.apache.camel.component.ribbon.cloud.RibbonLoadBalancer"> + <constructor-arg index="0"> + <bean class="org.apache.camel.component.ribbon.RibbonConfiguration"/> + </constructor-arg> + </bean> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <!-- service call configuration to use ribbon --> + <serviceCallConfiguration id="ribbon" loadBalancerRef="balancer" serviceDiscoveryRef="discovery"/> + + <route> + <from uri="direct:start"/> + <serviceCall name="myService"/> + <to uri="mock:result"/> + </route> + + <route> + <from uri="jetty:http://localhost:9090"/> + <to uri="mock:9090"/> + <transform> + <constant>9090</constant> + </transform> + </route> + + <route> + <from uri="jetty:http://localhost:9091"/> + <to uri="mock:9091"/> + <transform> + <constant>9091</constant> + </transform> + </route> + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.xml b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.xml new file mode 100644 index 0000000..48ce72a --- /dev/null +++ b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/cloud/SpringDslRibbonServiceCallRouteTest.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring + http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <serviceCall name="myService"> + <!-- static list of servers --> + <staticServiceDiscovery> + <servers>localhost:9090,localhost:9091</servers> + </staticServiceDiscovery> + + <!-- enable ribbon load balancer --> + <ribbonLoadBalancer clientName="myClient"/> + </serviceCall> + <to uri="mock:result"/> + </route> + + <route> + <from uri="jetty:http://localhost:9090"/> + <to uri="mock:9090"/> + <transform> + <constant>9090</constant> + </transform> + </route> + + <route> + <from uri="jetty:http://localhost:9091"/> + <to uri="mock:9091"/> + <transform> + <constant>9091</constant> + </transform> + </route> + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml deleted file mode 100644 index 6b2df8d..0000000 --- a/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml +++ /dev/null @@ -1,60 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd - "> - - <!-- setup a static ribbon server list with these 2 servers to start with --> - <!-- call the build method with the argument below --> - <bean id="servers" class="org.apache.camel.component.ribbon.processor.RibbonServiceCallStaticServerListStrategy" - factory-method="build"> - <constructor-arg index="0" value="localhost:9090,localhost:9091"/> - </bean> - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - - <!-- service call configuration to use ribbon --> - <ribbonConfiguration id="ribbon" serverListStrategyRef="servers"/> - - <route> - <from uri="direct:start"/> - <serviceCall name="myService"/> - <to uri="mock:result"/> - </route> - - <route> - <from uri="jetty:http://localhost:9090"/> - <to uri="mock:9090"/> - <transform> - <constant>9090</constant> - </transform> - </route> - - <route> - <from uri="jetty:http://localhost:9091"/> - <to uri="mock:9091"/> - <transform> - <constant>9091</constant> - </transform> - </route> - </camelContext> - -</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java new file mode 100644 index 0000000..194f518 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.springframework.cloud.client.DefaultServiceInstance; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; + +public class CamelCloudDiscoveryClient implements DiscoveryClient { + private final String description; + private final Map<String, List<ServiceInstance>> services; + private ServiceInstance localInstance; + + public CamelCloudDiscoveryClient(String description) { + this(description, Collections.emptyMap()); + } + + public CamelCloudDiscoveryClient(String description, Map<String, List<ServiceInstance>> services) { + this.description = description; + this.services = new LinkedHashMap<>(services); + this.localInstance = null; + } + + @Override + public String description() { + return description; + } + + @Override + public ServiceInstance getLocalServiceInstance() { + return this.localInstance; + } + + @Override + public List<ServiceInstance> getInstances(String serviceId) { + return services.get(serviceId); + } + + @Override + public List<String> getServices() { + return new ArrayList<>(services.keySet()); + } + + public CamelCloudDiscoveryClient addServiceInstance(ServiceInstance instance) { + services.computeIfAbsent(instance.getServiceId(), key -> new LinkedList<>()).add(instance); + return this; + } + + public CamelCloudDiscoveryClient addServiceInstance(String serviceId, String host, int port) { + return addServiceInstance(new DefaultServiceInstance(serviceId, host, port, false)); + } + + public CamelCloudDiscoveryClient setLocalServiceInstance(ServiceInstance instance) { + this.localInstance = instance; + return this; + } + + public CamelCloudDiscoveryClient setLocalServiceInstance(String serviceId, String host, int port) { + return setLocalServiceInstance(new DefaultServiceInstance(serviceId, host, port, false)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java new file mode 100644 index 0000000..08a73b8 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; +import org.apache.camel.cloud.LoadBalancer; +import org.apache.camel.cloud.LoadBalancerFunction; +import org.apache.camel.impl.cloud.DefaultServiceDefinition; +import org.apache.camel.support.ServiceSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; + +public class CamelCloudLoadBalancer extends ServiceSupport implements CamelContextAware, LoadBalancer { + private static final Logger LOGGER = LoggerFactory.getLogger(CamelCloudLoadBalancer.class); + + private final LoadBalancerClient loadBalancerClient; + private CamelContext camelContext; + + public CamelCloudLoadBalancer(LoadBalancerClient loadBalancerClient) { + this.loadBalancerClient = loadBalancerClient; + } + + @Override + public CamelContext getCamelContext() { + return camelContext; + } + + @Override + public void setCamelContext(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + protected void doStart() throws Exception { + ObjectHelper.notNull(camelContext, "camelContext"); + ObjectHelper.notNull(loadBalancerClient, "loadBalancerClient"); + + LOGGER.info("ServiceCall is using cloud load balancer of type: {}", + loadBalancerClient.getClass()); + } + + @Override + protected void doStop() throws Exception { + } + + @Override + public <T> T process(String serviceName, LoadBalancerFunction<T> function) throws Exception { + return loadBalancerClient.execute( + serviceName, + i -> function.apply(new DefaultServiceDefinition(i.getServiceId(), i.getHost(), i.getPort(), i.getMetadata())) + ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java new file mode 100644 index 0000000..3896494 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.camel.cloud.ServiceDefinition; +import org.apache.camel.impl.cloud.DefaultServiceDefinition; +import org.apache.camel.impl.cloud.DefaultServiceDiscovery; +import org.springframework.cloud.client.discovery.DiscoveryClient; + +public class CamelCloudServiceDiscovery extends DefaultServiceDiscovery { + private final List<DiscoveryClient> clients; + + public CamelCloudServiceDiscovery(List<DiscoveryClient> clients) { + this.clients = new ArrayList<>(clients); + } + + @Override + public List<ServiceDefinition> getInitialListOfServices(String name) { + return getServers(name); + } + + @Override + public List<ServiceDefinition> getUpdatedListOfServices(String name) { + return getServers(name); + } + + private List<ServiceDefinition> getServers(String name) { + return clients.stream() + .flatMap(c -> c.getInstances(name).stream()) + .map(s -> new DefaultServiceDefinition(s.getServiceId(), s.getHost(), s.getPort(), s.getMetadata())) + .collect(Collectors.toList()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java new file mode 100644 index 0000000..dd1124e --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.cloud.servicecall") +public class ServiceCallConfigurationProperties { + private boolean enabled = true; + private LoadBalancer loadBalancer = new LoadBalancer(); + private ServiceDiscovery serviceDiscovery = new ServiceDiscovery(); + private ServiceFilter serviceFilter = new ServiceFilter(); + private ServiceChooser serviceChooser = new ServiceChooser(); + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public LoadBalancer getLoadBalancer() { + return loadBalancer; + } + + public ServiceDiscovery getServiceDiscovery() { + return serviceDiscovery; + } + + public ServiceFilter getServiceFilter() { + return serviceFilter; + } + + public ServiceChooser getServiceChooser() { + return serviceChooser; + } + + // ***************************************** + // Nested configurations + // ***************************************** + + public static class LoadBalancer { + private boolean enabled = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + } + + public static class ServiceDiscovery { + private boolean enabled = true; + private Map<String, String> services = new HashMap<>(); + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public Map<String, String> getServices() { + return services; + } + } + + public static class ServiceFilter { + private boolean enabled = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + } + + public static class ServiceChooser { + private boolean enabled = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java new file mode 100644 index 0000000..32b66d2 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import org.apache.camel.cloud.LoadBalancer; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; + +@Configuration +@ConditionalOnBean({ CamelCloudAutoConfiguration.class, LoadBalancerClient.class }) +@AutoConfigureAfter(LoadBalancerAutoConfiguration.class) +@EnableConfigurationProperties(ServiceCallConfigurationProperties.class) +public class ServiceCallLoadBalancerAutoConfiguration { + @Lazy + @Scope("prototype") + @Bean(name = "cloud-load-balancer") + @Conditional(ServiceCallLoadBalancerAutoConfiguration.LoadBalancerCondition.class) + public LoadBalancer cloudLoadBalancer(LoadBalancerClient loadBalancerClient) { + return new CamelCloudLoadBalancer(loadBalancerClient); + } + + public static class LoadBalancerCondition extends GroupCondition { + public LoadBalancerCondition() { + super( + "camel.cloud.servicecall", + "camel.cloud.servicecall.load-balancer" + ); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java new file mode 100644 index 0000000..dae38a0 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import org.apache.camel.cloud.ServiceChooser; +import org.apache.camel.impl.cloud.RandomServiceChooser; +import org.apache.camel.impl.cloud.RoundRobinServiceChooser; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; +import org.springframework.core.annotation.Order; + +@Configuration +@ConditionalOnBean(CamelCloudAutoConfiguration.class) +@EnableConfigurationProperties(ServiceCallConfigurationProperties.class) +public class ServiceCallServiceChooserAutoConfiguration { + + @Lazy + @Scope("prototype") + @Order(1) + @Bean(name = "round-robin-service-chooser") + @Conditional(ServiceCallServiceChooserAutoConfiguration.ServiceChooserCondition.class) + public ServiceChooser roundRobinLoadBalancer() { + return new RoundRobinServiceChooser(); + } + + @Lazy + @Scope("prototype") + @Order(2) + @Bean(name = "random-service-chooser") + @Conditional(ServiceCallServiceChooserAutoConfiguration.ServiceChooserCondition.class) + public ServiceChooser randomLoadBalancer() { + return new RandomServiceChooser(); + } + + public static class ServiceChooserCondition extends GroupCondition { + public ServiceChooserCondition() { + super( + "camel.cloud.servicecall", + "camel.cloud.servicecall.service-chooser" + ); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java new file mode 100644 index 0000000..4934465 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import java.util.List; +import java.util.Map; + +import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.util.StringHelper; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; + +@Configuration +@EnableConfigurationProperties(ServiceCallConfigurationProperties.class) +public class ServiceCallServiceDiscoveryAutoConfiguration { + @Lazy + @Scope("prototype") + @Bean(name = "service-discovery-client") + @Conditional(ServiceCallServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class) + public DiscoveryClient serviceDiscoveryClient(ServiceCallConfigurationProperties properties) { + CamelCloudDiscoveryClient client = new CamelCloudDiscoveryClient("service-discovery-client"); + + Map<String, String> services = properties.getServiceDiscovery().getServices(); + for (Map.Entry<String, String> entry : services.entrySet()) { + + String[] parts = entry.getValue().split(","); + for (String part : parts) { + String host = StringHelper.before(part, ":"); + String port = StringHelper.after(part, ":"); + + client.addServiceInstance(entry.getKey(), host, Integer.parseInt(port)); + } + } + + return client; + } + + @Lazy + @Scope("prototype") + @Bean(name = "service-discovery") + @Conditional(ServiceCallServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class) + public ServiceDiscovery serviceDiscovery(List<DiscoveryClient> clients) { + return new CamelCloudServiceDiscovery(clients); + } + + public static class ServiceDiscoveryCondition extends GroupCondition { + public ServiceDiscoveryCondition() { + super( + "camel.cloud.servicecall", + "camel.cloud.servicecall.service-discovery" + ); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java new file mode 100644 index 0000000..d97c7d1 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import org.apache.camel.cloud.ServiceFilter; +import org.apache.camel.impl.cloud.AllServiceFilter; +import org.apache.camel.impl.cloud.HealthyServiceFilter; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; + +@Configuration +@EnableConfigurationProperties(ServiceCallConfigurationProperties.class) +public class ServiceCallServiceFilterAutoConfiguration { + @Lazy + @Scope("prototype") + @Bean(name = "service-filter-healthy") + @Conditional(ServiceCallServiceFilterAutoConfiguration.ServiceFilterCondition.class) + public ServiceFilter healthyServiceFilter() { + return new HealthyServiceFilter(); + } + + @Lazy + @Scope("prototype") + @Bean(name = "service-filter-all") + @Conditional(ServiceCallServiceFilterAutoConfiguration.ServiceFilterCondition.class) + public ServiceFilter allServiceFilter() { + return new AllServiceFilter(); + } + + public static class ServiceFilterCondition extends GroupCondition { + public ServiceFilterCondition() { + super( + "camel.cloud.servicecall", + "camel.cloud.servicecall.service-filter" + ); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallAutoConfiguration.java deleted file mode 100644 index 4f382e7..0000000 --- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallAutoConfiguration.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.spring.cloud.servicecall; - -import java.util.List; - -import org.apache.camel.impl.remote.RoundRobinServiceCallLoadBalancer; -import org.apache.camel.spi.ServiceCallLoadBalancer; -import org.apache.camel.spi.ServiceCallServer; -import org.apache.camel.spi.ServiceCallServerListStrategy; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.spring.boot.util.GroupCondition; -import org.apache.camel.spring.cloud.CamelCloudAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.context.annotation.Scope; -import org.springframework.core.annotation.Order; - -@Configuration -@ConditionalOnBean(CamelCloudAutoConfiguration.class) -public class CamelCloudServiceCallAutoConfiguration { - - // ****************************************** - // ServiceCall - ServerListStrategy - // ****************************************** - - @Lazy - @Scope("prototype") - @Bean(name = "server-list-strategy") - @ConditionalOnBean(DiscoveryClient.class) - @Conditional(CamelCloudServiceCallAutoConfiguration.ServerListStrategyCondition.class) - public ServiceCallServerListStrategy serverListStrategy(List<DiscoveryClient> clients) { - return new CamelCloudServiceCallServerListStrategy(clients); - } - - public static class ServerListStrategyCondition extends GroupCondition { - public ServerListStrategyCondition() { - super( - "camel.cloud.servicecall", - "camel.cloud.servicecall.server-list-strategy" - ); - } - } - - // ****************************************** - // ServiceCall - Load Balancer - // ****************************************** - - @Lazy - @Scope("prototype") - @Order(1) - @Bean(name = "round-robin-load-balancer") - @Conditional(CamelCloudServiceCallAutoConfiguration.LoadBalancerCondition.class) - public ServiceCallLoadBalancer<ServiceCallServer> roundRobinLoadBalancer() { - return new RoundRobinServiceCallLoadBalancer<>(); - } - - @Lazy - @Scope("prototype") - @Order(2) - @Bean(name = "random-load-balancer") - @Conditional(CamelCloudServiceCallAutoConfiguration.LoadBalancerCondition.class) - public ServiceCallLoadBalancer<ServiceCallServer> randomLoadBalancer() { - return new RoundRobinServiceCallLoadBalancer<>(); - } - - public static class LoadBalancerCondition extends GroupCondition { - public LoadBalancerCondition() { - super( - "camel.cloud.servicecall", - "camel.cloud.servicecall.load-balancer" - ); - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallConfigurationProperties.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallConfigurationProperties.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallConfigurationProperties.java deleted file mode 100644 index 548bcd7..0000000 --- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallConfigurationProperties.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.spring.cloud.servicecall; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "camel.cloud.servicecall") -public class CamelCloudServiceCallConfigurationProperties { - private boolean enabled = true; - private LoadBalancer loadBalancer; - private ServerListStrategy serverListStrategy; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public LoadBalancer getLoadBalancer() { - return loadBalancer; - } - - public void setLoadBalancer(LoadBalancer loadBalancer) { - this.loadBalancer = loadBalancer; - } - - public ServerListStrategy getServerListStrategy() { - return serverListStrategy; - } - - public void setServerListStrategy(ServerListStrategy serverListStrategy) { - this.serverListStrategy = serverListStrategy; - } - - // ***************************************** - // Nested configurations - // ***************************************** - - public static class LoadBalancer { - private boolean enabled = true; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - } - - public static class ServerListStrategy { - private boolean enabled = true; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessor.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessor.java deleted file mode 100644 index bb965ab..0000000 --- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessor.java +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.spring.cloud.servicecall; - -import java.io.IOException; - -import org.apache.camel.AsyncCallback; -import org.apache.camel.AsyncProcessor; -import org.apache.camel.CamelContext; -import org.apache.camel.CamelContextAware; -import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; -import org.apache.camel.Expression; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.Traceable; -import org.apache.camel.impl.remote.DefaultServiceCallExpression; -import org.apache.camel.impl.remote.ServiceCallConstants; -import org.apache.camel.processor.SendDynamicProcessor; -import org.apache.camel.spi.IdAware; -import org.apache.camel.support.ServiceSupport; -import org.apache.camel.util.AsyncProcessorHelper; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.util.ServiceHelper; -import org.apache.camel.util.StringHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; - -public class CamelCloudServiceCallProcessor extends ServiceSupport implements AsyncProcessor, CamelContextAware, Traceable, IdAware { - private static final Logger LOG = LoggerFactory.getLogger(CamelCloudServiceCallProcessor.class); - - private final ExchangePattern exchangePattern; - private final String name; - private final String scheme; - private final String uri; - private final String contextPath; - private final LoadBalancerClient loadBalancerClient; - private CamelContext camelContext; - private String id; - private Expression serviceCallExpression; - private SendDynamicProcessor processor; - - public CamelCloudServiceCallProcessor(String name, String scheme, String uri, ExchangePattern exchangePattern, LoadBalancerClient loadBalancerClient) { - this.uri = uri; - this.exchangePattern = exchangePattern; - this.loadBalancerClient = loadBalancerClient; - - // setup from the provided name which can contain scheme and context-path information as well - String serviceName; - if (name.contains("/")) { - serviceName = StringHelper.before(name, "/"); - this.contextPath = StringHelper.after(name, "/"); - } else if (name.contains("?")) { - serviceName = StringHelper.before(name, "?"); - this.contextPath = StringHelper.after(name, "?"); - } else { - serviceName = name; - this.contextPath = null; - } - if (serviceName.contains(":")) { - this.scheme = StringHelper.before(serviceName, ":"); - this.name = StringHelper.after(serviceName, ":"); - } else { - this.scheme = scheme; - this.name = serviceName; - } - - this.serviceCallExpression = new DefaultServiceCallExpression( - this.name, - this.scheme, - this.contextPath, - this.uri); - } - - @Override - public CamelContext getCamelContext() { - return camelContext; - } - - @Override - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - @Override - public String getTraceLabel() { - return id; - } - - public String getName() { - return name; - } - - public String getScheme() { - return scheme; - } - - public String getContextPath() { - return contextPath; - } - - public String getUri() { - return uri; - } - - public ExchangePattern getExchangePattern() { - return exchangePattern; - } - - public void setServiceCallExpression(Expression serviceCallExpression) { - this.serviceCallExpression = serviceCallExpression; - } - - public Expression getServiceCallExpression() { - return serviceCallExpression; - } - - public CamelCloudServiceCallProcessor serviceCallExpression(Expression serviceCallExpression) { - setServiceCallExpression(serviceCallExpression); - return this; - } - - public AsyncProcessor getProcessor() { - return processor; - } - - @Override - protected void doStart() throws Exception { - StringHelper.notEmpty(getName(), "name", "serviceName"); - ObjectHelper.notNull(camelContext, "camelContext"); - ObjectHelper.notNull(serviceCallExpression, "serviceCallExpression"); - ObjectHelper.notNull(loadBalancerClient, "loadBalancerClient"); - - LOG.info("ServiceCall with service name: {}", name); - - processor = new SendDynamicProcessor(uri, serviceCallExpression); - processor.setCamelContext(getCamelContext()); - if (exchangePattern != null) { - processor.setPattern(exchangePattern); - } - - ServiceHelper.startServices(processor); - } - - @Override - protected void doStop() throws Exception { - } - - @Override - public void process(Exchange exchange) throws Exception { - AsyncProcessorHelper.process(this, exchange); - } - - @Override - public boolean process(final Exchange exchange, final AsyncCallback callback) { - if (exchange.getException() != null) { - callback.done(true); - return true; - } - - try { - return loadBalancerClient.execute( - exchange.getIn().getHeader(ServiceCallConstants.SERVICE_NAME, name, String.class), - instance -> { - exchange.getIn().setHeader(ServiceCallConstants.SERVER_IP, instance.getHost()); - exchange.getIn().setHeader(ServiceCallConstants.SERVER_PORT, instance.getPort()); - exchange.getIn().setHeader(ServiceCallConstants.SERVICE_NAME, instance.getServiceId()); - return processor.process(exchange, callback); - } - ); - } catch (IOException e) { - throw new RuntimeCamelException(e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessorFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessorFactory.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessorFactory.java deleted file mode 100644 index 2db3ffe..0000000 --- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallProcessorFactory.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.spring.cloud.servicecall; - -import java.util.Set; -import java.util.function.Supplier; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExchangePattern; -import org.apache.camel.Processor; -import org.apache.camel.impl.remote.AbstractServiceCallProcessorFactory; -import org.apache.camel.impl.remote.DefaultServiceCallProcessor; -import org.apache.camel.model.remote.ServiceCallConfigurationDefinition; -import org.apache.camel.model.remote.ServiceCallDefinition; -import org.apache.camel.spi.RouteContext; -import org.apache.camel.spi.ServiceCallLoadBalancer; -import org.apache.camel.spi.ServiceCallServer; -import org.apache.camel.spi.ServiceCallServerListStrategy; -import org.apache.camel.util.CamelContextHelper; -import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; - -public class CamelCloudServiceCallProcessorFactory extends AbstractServiceCallProcessorFactory { - @Override - protected Processor createProcessor(RouteContext routeContext, ServiceCallDefinition definition) throws Exception { - String name = definition.getName(); - String uri = definition.getUri(); - ExchangePattern mep = definition.getPattern(); - CamelContext camelContext = routeContext.getCamelContext(); - - ServiceCallConfigurationDefinition config = definition.getServiceCallConfiguration(); - ServiceCallConfigurationDefinition configRef = null; - if (definition.getServiceCallConfigurationRef() != null) { - // lookup in registry first - configRef = CamelContextHelper.lookup(camelContext, definition.getServiceCallConfigurationRef(), ServiceCallConfigurationDefinition.class); - if (configRef == null) { - // and fallback as service configuration - camelContext.getServiceCallConfiguration(definition.getServiceCallConfigurationRef(), ServiceCallConfigurationDefinition.class); - } - } - - // if no configuration explicit configured then use default - if (config == null && configRef == null) { - config = camelContext.getServiceCallConfiguration(null, ServiceCallConfigurationDefinition.class); - } - if (config == null) { - // if no default then try to find if there configuration in the registry of the given type - Set<ServiceCallConfigurationDefinition> set = camelContext.getRegistry().findByType(ServiceCallConfigurationDefinition.class); - if (set.size() == 1) { - config = set.iterator().next(); - } - } - - - //if (config == null && configRef == null) { - // throw new IllegalStateException("The ServiceCall: " + definition + " must be configured before it can be used."); - //} - - String component = definition.getComponent(); - if (component == null) { - component = config != null ? config.getComponent() : null; - if (component == null && configRef != null) { - component = configRef.getComponent(); - } - } - - // lookup the load balancer to use (configured on EIP takes precedence vs configured on configuration) - Object lb = retrieveLoadBalancer(camelContext, definition, config, configRef); - if (lb == null) { - throw new IllegalArgumentException("Load balancer must be provided"); - } - - if (lb instanceof LoadBalancerClient) { - return new CamelCloudServiceCallProcessor(name, uri, component, mep, (LoadBalancerClient) lb); - } else if (lb instanceof ServiceCallLoadBalancer) { - - ServiceCallServerListStrategy<ServiceCallServer> sl = retrieveServerListStrategy(camelContext, definition, config, configRef); - if (lb == null) { - throw new IllegalArgumentException("Server list strategy must be provided"); - } - - DefaultServiceCallProcessor<ServiceCallServer> processor = new DefaultServiceCallProcessor<>(name, component, uri, mep); - processor.setLoadBalancer((ServiceCallLoadBalancer<ServiceCallServer>)lb); - processor.setServerListStrategy(sl); - - return processor; - } else { - throw new IllegalStateException( - "Unable to configure ServiceCall: LoadBalancer should be an instance of LoadBalancerClient or ServiceCallLoadBalancer, got " + lb.getClass().getName() - ); - } - } - - // ************************************************************************* - // Load Balancer - // ************************************************************************* - - private Object retrieveLoadBalancer( - CamelContext camelContext, ServiceCallDefinition definition, ServiceCallConfigurationDefinition config, ServiceCallConfigurationDefinition configRef) { - - // lookup the load balancer to use (configured on EIP takes precedence vs configured on configuration) - Object lb = retrieveLoadBalancer(camelContext, definition::getLoadBalancer, definition::getLoadBalancerRef); - if (lb == null && config != null) { - lb = retrieveLoadBalancer(camelContext, config::getLoadBalancer, config::getLoadBalancerRef); - } - if (lb == null && configRef != null) { - lb = retrieveLoadBalancer(camelContext, configRef::getLoadBalancer, configRef::getLoadBalancerRef); - } - - if (lb == null) { - Set<LoadBalancerClient> set = camelContext.getRegistry().findByType(LoadBalancerClient.class); - if (set.size() == 1) { - lb = set.iterator().next(); - } - } - - return lb; - } - - private Object retrieveLoadBalancer( - CamelContext camelContext, Supplier<Object> loadBalancerSupplier, Supplier<String> loadBalancerRefSupplier) { - - Object lb = null; - - if (loadBalancerSupplier != null) { - lb = loadBalancerSupplier.get(); - } - - if (lb == null && loadBalancerRefSupplier != null) { - String ref = loadBalancerRefSupplier.get(); - if (ref != null) { - lb = CamelContextHelper.lookup(camelContext, ref, LoadBalancerClient.class); - } - if (ref != null && lb == null) { - lb = CamelContextHelper.lookup(camelContext, ref, ServiceCallLoadBalancer.class); - } - } - - return lb; - } - - // ************************************************************************* - // Server List - // ************************************************************************* - - - private ServiceCallServerListStrategy retrieveServerListStrategy( - CamelContext camelContext, ServiceCallDefinition definition, ServiceCallConfigurationDefinition config, ServiceCallConfigurationDefinition configRef) { - - // lookup the server list strategy to use (configured on EIP takes precedence vs configured on configuration) - ServiceCallServerListStrategy sl = retrieveServerListStrategy(camelContext, definition::getServerListStrategy, definition::getServerListStrategyRef); - if (sl == null && config != null) { - sl = retrieveServerListStrategy(camelContext, config::getServerListStrategy, config::getServerListStrategyRef); - } - if (sl == null && configRef != null) { - sl = retrieveServerListStrategy(camelContext, configRef::getServerListStrategy, configRef::getServerListStrategyRef); - } - - if (sl == null) { - Set<ServiceCallServerListStrategy> set = camelContext.getRegistry().findByType(ServiceCallServerListStrategy.class); - if (set.size() == 1) { - sl = set.iterator().next(); - } - } - - return sl; - } - - private ServiceCallServerListStrategy retrieveServerListStrategy( - CamelContext camelContext, Supplier<ServiceCallServerListStrategy> serverListSupplier, Supplier<String> serverListSupplierRef) { - - ServiceCallServerListStrategy sl = null; - - if (serverListSupplier != null) { - sl = serverListSupplier.get(); - } - - if (sl == null && serverListSupplierRef != null) { - String ref = serverListSupplierRef.get(); - if (ref != null) { - sl = CamelContextHelper.lookup(camelContext, ref, ServiceCallServerListStrategy.class); - } - } - - return sl; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallServerListStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallServerListStrategy.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallServerListStrategy.java deleted file mode 100644 index 3f30b6c..0000000 --- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/servicecall/CamelCloudServiceCallServerListStrategy.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.camel.spring.cloud.servicecall; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.camel.impl.remote.DefaultServiceCallServer; -import org.apache.camel.impl.remote.DefaultServiceCallServerListStrategy; -import org.apache.camel.spi.ServiceCallServer; -import org.springframework.cloud.client.discovery.DiscoveryClient; - -public class CamelCloudServiceCallServerListStrategy extends DefaultServiceCallServerListStrategy<ServiceCallServer> { - private final List<DiscoveryClient> clients; - - public CamelCloudServiceCallServerListStrategy(List<DiscoveryClient> clients) { - this.clients = new ArrayList<>(clients); - } - - @Override - public List<ServiceCallServer> getInitialListOfServers(String name) { - return getServers(name); - } - - @Override - public List<ServiceCallServer> getUpdatedListOfServers(String name) { - return getServers(name); - } - - private List<ServiceCallServer> getServers(String name) { - return clients.stream() - .flatMap(c -> c.getInstances(name).stream()) - .map(s -> new DefaultServiceCallServer(s.getHost(), s.getPort(), s.getMetadata())) - .collect(Collectors.toList()); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition b/components/camel-spring-cloud/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition deleted file mode 100644 index c5f036b..0000000 --- a/components/camel-spring-cloud/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.spring.cloud.servicecall.CamelCloudServiceCallProcessorFactory http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories b/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories index 429fa52..d925094 100644 --- a/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories +++ b/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories @@ -17,4 +17,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.apache.camel.spring.cloud.CamelCloudAutoConfiguration,\ -org.apache.camel.spring.cloud.servicecall.CamelCloudServiceCallAutoConfiguration +org.apache.camel.spring.cloud.ServiceCallServiceChooserAutoConfiguration,\ +org.apache.camel.spring.cloud.ServiceCallServiceDiscoveryAutoConfiguration,\ +org.apache.camel.spring.cloud.ServiceCallLoadBalancerAutoConfiguration