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/04/19 18:19:22 UTC

[03/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is using hystrix

CAMEL-9879: Circuit Breaker EIP - That is using hystrix


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

Branch: refs/heads/hys
Commit: ccb70f6247175b49ecea110a71a053ef03e6fe6a
Parents: 4f16c26
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 16:18:58 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 16:18:58 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/model/HystrixDefinition.java   | 40 ++++++++++++++++++++
 .../hystrix/processor/HystrixProcessor.java     |  3 +-
 .../processor/HystrixProcessorFactory.java      | 19 ++++++++--
 3 files changed, 56 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ccb70f62/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
index fa91362..b5fc6a8 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
@@ -36,6 +36,13 @@ import org.apache.camel.spi.RouteContext;
 @XmlAccessorType(XmlAccessType.FIELD)
 public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
 
+    public static final String DEFAULT_GROUP_KEY = "CamelHystrix";
+    public static final String DEFAULT_THREAD_POOL_KEY = "CamelHystrix";
+
+    @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+    private String groupKey;
+    @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+    private String threadPoolKey;
     @XmlElement
     private HystrixConfigurationDefinition hystrixConfiguration;
     @XmlElement
@@ -120,6 +127,23 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
     // Getter/Setter
     // -------------------------------------------------------------------------
 
+
+    public String getGroupKey() {
+        return groupKey;
+    }
+
+    public void setGroupKey(String groupKey) {
+        this.groupKey = groupKey;
+    }
+
+    public String getThreadPoolKey() {
+        return threadPoolKey;
+    }
+
+    public void setThreadPoolKey(String threadPoolKey) {
+        this.threadPoolKey = threadPoolKey;
+    }
+
     public HystrixConfigurationDefinition getHystrixConfiguration() {
         return hystrixConfiguration;
     }
@@ -156,6 +180,22 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
     // -------------------------------------------------------------------------
 
     /**
+     * Sets the group key to use. The default value is CamelHystrix.
+     */
+    public HystrixDefinition groupKey(String groupKey) {
+        setGroupKey(groupKey);
+        return this;
+    }
+
+    /**
+     * Sets the thread pool key to use. The default value is CamelHystrix.
+     */
+    public HystrixDefinition threadPoolKey(String threadPoolKey) {
+        setThreadPoolKey(threadPoolKey);
+        return this;
+    }
+
+    /**
      * Configures the Hystrix EIP
      * <p/>
      * Use <tt>end</tt> when configuration is complete, to return back to the Hystrix EIP.

http://git-wip-us.apache.org/repos/asf/camel/blob/ccb70f62/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
index 8f836c0..1b497bf 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
@@ -42,8 +42,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
     private final AsyncProcessor fallback;
     private final Expression cacheKey;
 
-    public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback, Expression cacheKey) {
-        this.id = id;
+    public HystrixProcessor(HystrixCommand.Setter setter, Processor processor, Processor fallback, Expression cacheKey) {
         this.setter = setter;
         this.processor = AsyncProcessorConverterHelper.convert(processor);
         this.fallback = AsyncProcessorConverterHelper.convert(fallback);

http://git-wip-us.apache.org/repos/asf/camel/blob/ccb70f62/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
index 1389438..5317db0 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.hystrix.processor;
 import com.netflix.hystrix.HystrixCommand;
 import com.netflix.hystrix.HystrixCommandGroupKey;
 import com.netflix.hystrix.HystrixCommandProperties;
+import com.netflix.hystrix.HystrixThreadPoolKey;
 import com.netflix.hystrix.HystrixThreadPoolProperties;
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
@@ -44,7 +45,6 @@ public class HystrixProcessorFactory implements ProcessorFactory {
     public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
         if (definition instanceof HystrixDefinition) {
             HystrixDefinition cb = (HystrixDefinition) definition;
-            String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
 
             // create the regular and fallback processors
             Processor processor = cb.createChildProcessor(routeContext, true);
@@ -53,8 +53,20 @@ public class HystrixProcessorFactory implements ProcessorFactory {
                 fallback = cb.getFallback().createProcessor(routeContext);
             }
 
+            // group and thread pool keys to use
+            String groupKey = HystrixDefinition.DEFAULT_GROUP_KEY;
+            String threadPoolKey = HystrixDefinition.DEFAULT_THREAD_POOL_KEY;
+            if (cb.getGroupKey() != null) {
+                groupKey = cb.getGroupKey();
+            }
+            if (cb.getThreadPoolKey() != null) {
+                threadPoolKey = cb.getThreadPoolKey();
+            }
+
             // create setter using the default options
-            HystrixCommand.Setter setter = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id));
+            HystrixCommand.Setter setter = HystrixCommand.Setter
+                    .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
+                    .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolKey));
             HystrixCommandProperties.Setter command = HystrixCommandProperties.Setter();
             setter.andCommandPropertiesDefaults(command);
             HystrixThreadPoolProperties.Setter threadPool = HystrixThreadPoolProperties.Setter();
@@ -77,7 +89,7 @@ public class HystrixProcessorFactory implements ProcessorFactory {
                 cacheKey = cb.getCacheKey().createExpression(routeContext);
             }
 
-            return new HystrixProcessor(id, setter, processor, fallback, cacheKey);
+            return new HystrixProcessor(setter, processor, fallback, cacheKey);
         } else {
             return null;
         }
@@ -151,7 +163,6 @@ public class HystrixProcessorFactory implements ProcessorFactory {
         if (config.getRequestLogEnabled() != null) {
             command.withRequestLogEnabled(config.getRequestLogEnabled());
         }
-        // thread pool
         if (config.getCorePoolSize() != null) {
             threadPool.withCoreSize(config.getCorePoolSize());
         }