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:35 UTC
[16/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/a192ff68
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a192ff68
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a192ff68
Branch: refs/heads/master
Commit: a192ff68ea3f1607586a999e3cfb3b51133696e5
Parents: ca8f07c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 13:43:23 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/HystrixDefinition.java | 27 +++++++++
.../processor/HystrixProcessorFactory.java | 6 +-
.../HystrixRouteFallbackDisabledTest.java | 58 --------------------
3 files changed, 32 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a192ff68/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 734b913..146ddbe 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
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
@@ -40,6 +41,8 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
protected List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
@XmlElement
private FallbackDefinition fallback;
+ @XmlAttribute
+ private String hystrixConfigurationRef;
public HystrixDefinition() {
}
@@ -130,6 +133,14 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
this.hystrixConfiguration = hystrixConfiguration;
}
+ public String getHystrixConfigurationRef() {
+ return hystrixConfigurationRef;
+ }
+
+ public void setHystrixConfigurationRef(String hystrixConfigurationRef) {
+ this.hystrixConfigurationRef = hystrixConfigurationRef;
+ }
+
// Fluent API
// -------------------------------------------------------------------------
@@ -152,4 +163,20 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
return hystrixConfiguration;
}
+ /**
+ * Configures the Hystrix EIP using the given configuration
+ */
+ public HystrixDefinition configure(HystrixConfigurationDefinition configuration) {
+ hystrixConfiguration = configuration;
+ return this;
+ }
+
+ /**
+ * Refers to a hystrix configuration to use for configuring the Hystrix EIP.
+ */
+ public HystrixDefinition configure(String ref) {
+ hystrixConfigurationRef = ref;
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a192ff68/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 8e4a7f1..bc1cca8 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
@@ -26,6 +26,7 @@ import org.apache.camel.model.HystrixDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.CamelContextHelper;
/**
* To integrate camel-hystrix with the Camel routes using the Hystrix EIP.
@@ -59,8 +60,11 @@ public class HystrixProcessorFactory implements ProcessorFactory {
setter.andThreadPoolPropertiesDefaults(threadPool);
// any custom configuration then override the setter
- if (cb.getHystrixConfiguration() != null) {
+ if (cb.getHystrixConfiguration() != null || cb.getHystrixConfigurationRef() != null) {
HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+ if (config == null && cb.getHystrixConfigurationRef() != null) {
+ config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+ }
// command
if (config.getCircuitBreakerEnabled() != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/a192ff68/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackDisabledTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackDisabledTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackDisabledTest.java
deleted file mode 100644
index 9e81ce9..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackDisabledTest.java
+++ /dev/null
@@ -1,58 +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.hystrix.processor;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixRouteFallbackDisabledTest extends CamelTestSupport {
-
- @Test
- public void testHystrix() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(0);
-
- try {
- template.sendBody("direct:start", "Hello World");
- fail("Should have thrown exception");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- }
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrix().configure().fallbackEnabled(false).end()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo").errorHandler(noErrorHandler())
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-
-}