You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/05/23 08:05:09 UTC

[22/34] camel git commit: CAMEL-9683: Started on camel-ribbon

CAMEL-9683: Started on camel-ribbon


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da936819
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da936819
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da936819

Branch: refs/heads/remoteServiceCall
Commit: da9368198555770e29d4899ae0f5f9172f045a5d
Parents: d2495c7
Author: Claus Ibsen <da...@apache.org>
Authored: Mon May 16 14:50:01 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon May 23 09:27:15 2016 +0200

----------------------------------------------------------------------
 .../component/ribbon/RibbonConfiguration.java   | 10 ++++++++++
 .../processor/RibbonServiceCallProcessor.java   | 18 +++++++++++++++++-
 ...bbonServiceCallStaticServerListStrategy.java | 20 ++++++++++++++++++++
 .../SpringRibbonServiceCallRouteTest.xml        |  2 +-
 4 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/da936819/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConfiguration.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConfiguration.java
index ead659e..21c1fe9 100644
--- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConfiguration.java
+++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConfiguration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.ribbon;
 
+import com.netflix.loadbalancer.IPing;
 import com.netflix.loadbalancer.IRule;
 
 public class RibbonConfiguration {
@@ -24,6 +25,7 @@ public class RibbonConfiguration {
     private String username;
     private String password;
     private IRule rule;
+    private IPing ping;
 
     public String getNamespace() {
         return namespace;
@@ -56,4 +58,12 @@ public class RibbonConfiguration {
     public void setRule(IRule rule) {
         this.rule = rule;
     }
+
+    public IPing getPing() {
+        return ping;
+    }
+
+    public void setPing(IPing ping) {
+        this.ping = ping;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/da936819/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java
index 290149a..ef97054 100644
--- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java
+++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java
@@ -22,6 +22,7 @@ import java.util.concurrent.RejectedExecutionException;
 import com.netflix.client.config.IClientConfig;
 import com.netflix.client.config.IClientConfigKey;
 import com.netflix.loadbalancer.DummyPing;
+import com.netflix.loadbalancer.IPing;
 import com.netflix.loadbalancer.IRule;
 import com.netflix.loadbalancer.PollingServerListUpdater;
 import com.netflix.loadbalancer.RoundRobinRule;
@@ -67,6 +68,7 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP
     private ServiceCallServerListStrategy<RibbonServer> serverListStrategy;
     private ZoneAwareLoadBalancer<RibbonServer> ribbonLoadBalancer;
     private IRule rule;
+    private IPing ping;
     private final RibbonServiceCallExpression serviceCallExpression;
     private Map<String, String> ribbonClientConfig;
     private SendDynamicProcessor processor;
@@ -96,6 +98,8 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP
         this.uri = uri;
         this.exchangePattern = exchangePattern;
         this.configuration = configuration;
+        this.rule = configuration.getRule();
+        this.ping = configuration.getPing();
         this.serviceCallExpression = new RibbonServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri);
     }
 
@@ -175,6 +179,14 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP
         this.rule = rule;
     }
 
+    public IPing getPing() {
+        return ping;
+    }
+
+    public void setPing(IPing ping) {
+        this.ping = ping;
+    }
+
     public Map<String, String> getRibbonClientConfig() {
         return ribbonClientConfig;
     }
@@ -200,6 +212,10 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP
             // use round robin rule by default
             rule = new RoundRobinRule();
         }
+        if (ping == null) {
+            // use dummy ping by default
+            ping = new DummyPing();
+        }
 
         // setup client config
         IClientConfig config = IClientConfig.Builder.newBuilder().build();
@@ -213,7 +229,7 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP
         }
 
         ServerListUpdater updater = new PollingServerListUpdater(config);
-        ribbonLoadBalancer = new ZoneAwareLoadBalancer<>(config, rule, new DummyPing(), (ServerList<RibbonServer>) serverListStrategy, null, updater);
+        ribbonLoadBalancer = new ZoneAwareLoadBalancer<>(config, rule, ping, (ServerList<RibbonServer>) serverListStrategy, null, updater);
 
         LOG.info("RibbonServiceCall at namespace: {} with service name: {} is using load balancer: {} and server list: {}", namespace, name, ribbonLoadBalancer, serverListStrategy);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/da936819/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java
index a836900..3630ac4 100644
--- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java
+++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java
@@ -25,11 +25,22 @@ import com.netflix.loadbalancer.ServerList;
 import org.apache.camel.spi.ServiceCallServerListStrategy;
 import org.apache.camel.util.ObjectHelper;
 
+/**
+ * A static list of known servers to be used by the Ribbon load balancer with the Camel Service Call EIP.
+ * <p/>
+ * You can implement custom implementations by existing this class and override the {@link #getUpdatedListOfServers()} that is called by Ribbon to refresh the known list
+ * of servers. For example to periodically query a remote server registry for a list of active servers.
+ */
 public class RibbonServiceCallStaticServerListStrategy extends AbstractServerList<RibbonServer> implements ServerList<RibbonServer>, ServiceCallServerListStrategy<RibbonServer> {
 
     private IClientConfig clientConfig;
     private final List<RibbonServer> servers = new ArrayList<>();
 
+    /**
+     * Build a {@link RibbonServiceCallStaticServerListStrategy} with the initial list of servers
+     *
+     * @param servers servers separated by comma in the format: host:port,host2:port,host3:port and so on.
+     */
     public static RibbonServiceCallStaticServerListStrategy build(String servers) {
         RibbonServiceCallStaticServerListStrategy answer = new RibbonServiceCallStaticServerListStrategy();
         String[] parts = servers.split(",");
@@ -49,14 +60,23 @@ public class RibbonServiceCallStaticServerListStrategy extends AbstractServerLis
         this.servers.addAll(servers);
     }
 
+    /**
+     * Add a server to the known list of servers.
+     */
     public void addServer(RibbonServer server) {
         servers.add(server);
     }
 
+    /**
+     * Add a server to the known list of servers.
+     */
     public void addServer(String host, int port) {
         servers.add(new RibbonServer(host, port));
     }
 
+    /**
+     * Remove an existing server from the list of known servers.
+     */
     public void removeServer(String host, int port) {
         servers.remove(new RibbonServer(host, port));
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/da936819/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
index 487fa0c..a06a670 100644
--- 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
@@ -36,7 +36,7 @@
 
     <route>
       <from uri="direct:start"/>
-      <serviceCall name="myService" serviceCallConfigurationRef="myConfig"/>
+      <serviceCall name="myService"/>
       <to uri="mock:result"/>
     </route>