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:20 UTC
[01/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Repository: camel
Updated Branches:
refs/heads/hys 4ee9ddecc -> f5b47783d
refs/heads/master 930d49af0 -> 62bbf9b23
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/e325750c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e325750c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e325750c
Branch: refs/heads/hys
Commit: e325750c2363496145d8446c9ede62ad23fbfa52
Parents: 4ee9dde
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 14:59:14 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 14:59:14 2016 +0200
----------------------------------------------------------------------
.../processor/HystrixProcessorFactory.java | 189 ++++++++++---------
1 file changed, 97 insertions(+), 92 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e325750c/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 bc1cca8..276275d 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
@@ -59,99 +59,15 @@ public class HystrixProcessorFactory implements ProcessorFactory {
HystrixThreadPoolProperties.Setter threadPool = HystrixThreadPoolProperties.Setter();
setter.andThreadPoolPropertiesDefaults(threadPool);
- // any custom configuration then override the setter
- if (cb.getHystrixConfiguration() != null || cb.getHystrixConfigurationRef() != null) {
+ // at first configure any shared options
+ if (cb.getHystrixConfigurationRef() != null) {
+ HystrixConfigurationDefinition config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+ configureHystrix(command, threadPool, config);
+ }
+ // then any local configured can override
+ if (cb.getHystrixConfiguration() != 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) {
- command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
- }
- if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
- command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
- }
- if (config.getCircuitBreakerForceClosed() != null) {
- command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
- }
- if (config.getCircuitBreakerForceOpen() != null) {
- command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
- }
- if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
- command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
- }
- if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
- command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
- }
- if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
- command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
- }
- if (config.getExecutionIsolationStrategy() != null) {
- command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
- }
- if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
- command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
- }
- if (config.getExecutionTimeoutInMilliseconds() != null) {
- command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
- }
- if (config.getExecutionTimeoutEnabled() != null) {
- command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
- }
- if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
- command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
- }
- if (config.getFallbackEnabled() != null) {
- command.withFallbackEnabled(config.getFallbackEnabled());
- }
- if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
- command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
- }
- if (config.getMetricsRollingPercentileBucketSize() != null) {
- command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
- }
- if (config.getMetricsRollingPercentileEnabled() != null) {
- command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
- }
- if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
- command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
- }
- if (config.getMetricsRollingPercentileWindowBuckets() != null) {
- command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
- }
- if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) {
- command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
- }
- if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
- command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
- }
- if (config.getRequestCacheEnabled() != null) {
- command.withRequestCacheEnabled(config.getRequestCacheEnabled());
- }
- if (config.getRequestLogEnabled() != null) {
- command.withRequestLogEnabled(config.getRequestLogEnabled());
- }
- // thread pool
- if (config.getCorePoolSize() != null) {
- threadPool.withCoreSize(config.getCorePoolSize());
- }
- if (config.getKeepAliveTime() != null) {
- threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
- }
- if (config.getMaxQueueSize() != null) {
- threadPool.withMaxQueueSize(config.getMaxQueueSize());
- }
- if (config.getQueueSizeRejectionThreshold() != null) {
- threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
- }
- if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
- threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
- }
- if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
- threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
- }
+ configureHystrix(command, threadPool, config);
}
return new HystrixProcessor(id, setter, processor, fallback);
@@ -159,4 +75,93 @@ public class HystrixProcessorFactory implements ProcessorFactory {
return null;
}
}
+
+ private void configureHystrix(HystrixCommandProperties.Setter command, HystrixThreadPoolProperties.Setter threadPool, HystrixConfigurationDefinition config) {
+ // command
+ if (config.getCircuitBreakerEnabled() != null) {
+ command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
+ }
+ if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
+ command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
+ }
+ if (config.getCircuitBreakerForceClosed() != null) {
+ command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
+ }
+ if (config.getCircuitBreakerForceOpen() != null) {
+ command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
+ }
+ if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
+ command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
+ }
+ if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
+ command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
+ }
+ if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getExecutionIsolationStrategy() != null) {
+ command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
+ }
+ if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
+ command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
+ }
+ if (config.getExecutionTimeoutInMilliseconds() != null) {
+ command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
+ }
+ if (config.getExecutionTimeoutEnabled() != null) {
+ command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
+ }
+ if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getFallbackEnabled() != null) {
+ command.withFallbackEnabled(config.getFallbackEnabled());
+ }
+ if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
+ command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileBucketSize() != null) {
+ command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
+ }
+ if (config.getMetricsRollingPercentileEnabled() != null) {
+ command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
+ }
+ if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
+ command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileWindowBuckets() != null) {
+ command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
+ }
+ if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) {
+ command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
+ command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
+ }
+ if (config.getRequestCacheEnabled() != null) {
+ command.withRequestCacheEnabled(config.getRequestCacheEnabled());
+ }
+ if (config.getRequestLogEnabled() != null) {
+ command.withRequestLogEnabled(config.getRequestLogEnabled());
+ }
+ // thread pool
+ if (config.getCorePoolSize() != null) {
+ threadPool.withCoreSize(config.getCorePoolSize());
+ }
+ if (config.getKeepAliveTime() != null) {
+ threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
+ }
+ if (config.getMaxQueueSize() != null) {
+ threadPool.withMaxQueueSize(config.getMaxQueueSize());
+ }
+ if (config.getQueueSizeRejectionThreshold() != null) {
+ threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
+ threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
+ threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
+ }
+ }
}
[11/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/f180fbeb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f180fbeb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f180fbeb
Branch: refs/heads/master
Commit: f180fbeb8e1344c7b7cd069fc97dff5fef3b73b7
Parents: 6f75174
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:49:34 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 29 +-------------------
.../hystrix/HystrixProcessorCommand.java | 13 +++++----
2 files changed, 9 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f180fbeb/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 495706f..22d48af 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -85,20 +85,13 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- // run this as if we run inside try .. catch so there is no regular Camel error handler
- exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
-
- // use our callback that does some cleanup when done
- AsyncCallback hystrixCallback = new HystrixAsyncCallback(exchange, callback);
-
HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, hystrixCallback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
try {
command.queue();
} catch (Throwable e) {
// error adding to queue, so set as error and we are done
exchange.setException(e);
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(true);
return true;
}
@@ -116,24 +109,4 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
// noop
}
- private static final class HystrixAsyncCallback implements AsyncCallback {
-
- private final Exchange exchange;
- private final AsyncCallback delegate;
-
- public HystrixAsyncCallback(Exchange exchange, AsyncCallback delegate) {
- this.exchange = exchange;
- this.delegate = delegate;
- }
-
- @Override
- public void done(boolean doneSync) {
- if (doneSync) {
- return;
- }
- // we are only done when called with false
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
- delegate.done(doneSync);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f180fbeb/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 299819e..1eec854 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -54,6 +54,7 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
try {
if (fallback != null) {
+ LOG.debug("Error occurred processing. Will now run fallback. Exception class: {} message: {}.", exception.getClass().getName(), exception.getMessage());
// store the last to endpoint as the failure endpoint
if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
@@ -66,14 +67,15 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
// run the fallback processor
try {
- LOG.debug("Running fallback: {}", exchange);
+ LOG.debug("Running fallback: {} with exchange: {}", fallback, exchange);
fallback.process(exchange, callback);
} catch (Exception e) {
exchange.setException(e);
}
}
} finally {
- LOG.debug("Running fallback: {} success", exchange);
+ LOG.debug("Running fallback: {} with exchange: {} done", fallback, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(false);
}
@@ -82,9 +84,9 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
@Override
protected Exchange run() throws Exception {
- LOG.debug("Running processor: {}", exchange);
+ LOG.debug("Running processor: {} with exchange: {}", processor, exchange);
- exchange.setProperty(Exchange.EXCEPTION_HANDLED, null);
+ // run this as if we run inside try .. catch so there is no regular Camel error handler
exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
try {
processor.process(exchange, callback);
@@ -98,7 +100,8 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
}
// no errors we are done
try {
- LOG.debug("Running processor: {} success", exchange);
+ LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
callback.done(false);
} catch (Throwable e) {
exchange.setException(e);
[23/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/62bbf9b2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62bbf9b2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62bbf9b2
Branch: refs/heads/master
Commit: 62bbf9b2393a450b97fb2782dcdf905bf029a6a2
Parents: d14dfbd
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 16:38:59 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../model/HystrixConfigurationDefinition.java | 39 +++++++++++++++++++-
.../apache/camel/model/HystrixDefinition.java | 28 +-------------
.../processor/HystrixProcessorFactory.java | 37 +++++++++++++------
.../processor/HystrixRouteConfigTest.java | 2 +-
.../processor/SpringHystrixRouteConfigTest.xml | 2 +-
5 files changed, 67 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/62bbf9b2/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
index a47b347..d4e9f52 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
@@ -33,9 +33,14 @@ import org.apache.camel.spi.Metadata;
@XmlAccessorType(XmlAccessType.FIELD)
public class HystrixConfigurationDefinition extends IdentifiedType {
+ public static final String DEFAULT_GROUP_KEY = "CamelHystrix";
+
@XmlTransient
private HystrixDefinition parent;
-
+ @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+ private String groupKey;
+ @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+ private String threadPoolKey;
@XmlAttribute
@Metadata(label = "command", defaultValue = "true")
private Boolean circuitBreakerEnabled;
@@ -134,6 +139,22 @@ public class HystrixConfigurationDefinition extends IdentifiedType {
// 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 Boolean getCircuitBreakerEnabled() {
return circuitBreakerEnabled;
}
@@ -363,6 +384,22 @@ public class HystrixConfigurationDefinition extends IdentifiedType {
// -------------------------------------------------------------------------
/**
+ * Sets the group key to use. The default value is CamelHystrix.
+ */
+ public HystrixConfigurationDefinition groupKey(String groupKey) {
+ setGroupKey(groupKey);
+ return this;
+ }
+
+ /**
+ * Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.
+ */
+ public HystrixConfigurationDefinition threadPoolKey(String threadPoolKey) {
+ setThreadPoolKey(threadPoolKey);
+ return this;
+ }
+
+ /**
* Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted.
* <p>
* This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it
http://git-wip-us.apache.org/repos/asf/camel/blob/62bbf9b2/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 b5fc6a8..3ca72f5 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,13 +36,6 @@ 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
@@ -127,23 +120,6 @@ 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;
}
@@ -183,7 +159,7 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
* Sets the group key to use. The default value is CamelHystrix.
*/
public HystrixDefinition groupKey(String groupKey) {
- setGroupKey(groupKey);
+ configure().groupKey(groupKey);
return this;
}
@@ -191,7 +167,7 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
* Sets the thread pool key to use. The default value is CamelHystrix.
*/
public HystrixDefinition threadPoolKey(String threadPoolKey) {
- setThreadPoolKey(threadPoolKey);
+ configure().threadPoolKey(threadPoolKey);
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/62bbf9b2/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 5317db0..26ea912 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
@@ -53,14 +53,29 @@ 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();
+ HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+ HystrixConfigurationDefinition configRef = null;
+ if (cb.getHystrixConfigurationRef() != null) {
+ configRef = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+ }
+
+ // group and thread pool keys to use they can be configured on configRef and config, so look there first, and if none then use default
+ String groupKey = null;
+ String threadPoolKey = null;
+ if (configRef != null) {
+ groupKey = configRef.getGroupKey();
+ threadPoolKey = configRef.getThreadPoolKey();
+ }
+ if (config != null && config.getGroupKey() != null) {
+ groupKey = config.getGroupKey();
+ threadPoolKey = config.getThreadPoolKey();
}
- if (cb.getThreadPoolKey() != null) {
- threadPoolKey = cb.getThreadPoolKey();
+ if (groupKey == null) {
+ groupKey = HystrixConfigurationDefinition.DEFAULT_GROUP_KEY;
+ }
+ if (threadPoolKey == null) {
+ // thread pool key should use same as group key as default
+ threadPoolKey = groupKey;
}
// create setter using the default options
@@ -73,13 +88,11 @@ public class HystrixProcessorFactory implements ProcessorFactory {
setter.andThreadPoolPropertiesDefaults(threadPool);
// at first configure any shared options
- if (cb.getHystrixConfigurationRef() != null) {
- HystrixConfigurationDefinition config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
- configureHystrix(command, threadPool, config);
+ if (configRef != null) {
+ configureHystrix(command, threadPool, configRef);
}
// then any local configured can override
- if (cb.getHystrixConfiguration() != null) {
- HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+ if (config != null) {
configureHystrix(command, threadPool, config);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/62bbf9b2/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
index 5faefb9..ebfa660 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
@@ -37,7 +37,7 @@ public class HystrixRouteConfigTest extends CamelTestSupport {
@Override
public void configure() throws Exception {
from("direct:start")
- .hystrix().configure().requestCacheEnabled(false).corePoolSize(5).end()
+ .hystrix().configure().groupKey("myCamelApp").requestCacheEnabled(false).corePoolSize(5).end()
.to("direct:foo")
.fallback()
.transform().constant("Fallback message")
http://git-wip-us.apache.org/repos/asf/camel/blob/62bbf9b2/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
index e7e964a..40a8ccb 100644
--- a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
@@ -25,7 +25,7 @@
<route>
<from uri="direct:start"/>
<hystrix>
- <hystrixConfiguration requestCacheEnabled="false" corePoolSize="5"/>
+ <hystrixConfiguration groupKey="myCamelApp" requestCacheEnabled="false" corePoolSize="5"/>
<to uri="direct:foo"/>
<fallback>
<transform>
[22/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/89635686
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/89635686
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/89635686
Branch: refs/heads/master
Commit: 896356867058a7ce282ca8972d73e9d77e6c7437
Parents: a192ff68
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 14:02:26 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../model/HystrixConfigurationDefinition.java | 2 +-
.../blueprint/CamelContextFactoryBean.java | 2 +
.../processor/HystrixRouteConfigTest.java | 53 ++++++++++++++++++++
.../SpringHystrixRouteConfigRefTest.java | 40 +++++++++++++++
.../processor/SpringHystrixRouteConfigTest.java | 40 +++++++++++++++
.../SpringHystrixRouteConfigRefTest.xml | 49 ++++++++++++++++++
.../processor/SpringHystrixRouteConfigTest.xml | 47 +++++++++++++++++
.../camel/spring/CamelContextFactoryBean.java | 2 +
.../spring/handler/CamelNamespaceHandler.java | 4 +-
9 files changed, 237 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
index 5ea084e..c20d3ce 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
@@ -31,7 +31,7 @@ import org.apache.camel.spi.Metadata;
@Metadata(label = "eip,routing,circuitbreaker")
@XmlRootElement(name = "hystrixConfiguration")
@XmlAccessorType(XmlAccessType.FIELD)
-public class HystrixConfigurationDefinition {
+public class HystrixConfigurationDefinition extends IdentifiedType {
@XmlTransient
private HystrixDefinition parent;
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index aaebc7f..0c6e832 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -44,6 +44,7 @@ import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition;
import org.apache.camel.core.xml.CamelServiceExporterDefinition;
import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition;
import org.apache.camel.model.ContextScanDefinition;
+import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.InterceptDefinition;
import org.apache.camel.model.InterceptFromDefinition;
import org.apache.camel.model.InterceptSendToEndpointDefinition;
@@ -140,6 +141,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
@XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class, required = false)
private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy;
@XmlElements({
+ @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class, required = false),
@XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false),
@XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false),
@XmlElement(name = "proxy", type = CamelProxyFactoryBean.class, required = false),
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
new file mode 100644
index 0000000..5faefb9
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 HystrixRouteConfigTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix().configure().requestCacheEnabled(false).corePoolSize(5).end()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.java
new file mode 100644
index 0000000..dcf9dc0
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.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.hystrix.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 SpringHystrixRouteConfigRefTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.java
new file mode 100644
index 0000000..d0a52b1
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.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.hystrix.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 SpringHystrixRouteConfigTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.xml
new file mode 100644
index 0000000..887e81e
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigRefTest.xml
@@ -0,0 +1,49 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <hystrixConfiguration id="hysConfig" requestCacheEnabled="false" corePoolSize="5"/>
+
+ <route>
+ <from uri="direct:start"/>
+ <hystrix hystrixConfigurationRef="hysConfig">
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
new file mode 100644
index 0000000..e7e964a
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
@@ -0,0 +1,47 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <hystrix>
+ <hystrixConfiguration requestCacheEnabled="false" corePoolSize="5"/>
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 4c6af83..6179724 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -45,6 +45,7 @@ import org.apache.camel.core.xml.CamelProxyFactoryDefinition;
import org.apache.camel.core.xml.CamelServiceExporterDefinition;
import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition;
import org.apache.camel.model.ContextScanDefinition;
+import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.InterceptDefinition;
import org.apache.camel.model.InterceptFromDefinition;
import org.apache.camel.model.InterceptSendToEndpointDefinition;
@@ -150,6 +151,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
@XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class, required = false)
private CamelJMXAgentDefinition camelJMXAgent;
@XmlElements({
+ @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class, required = false),
@XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false),
@XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false),
@XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class, required = false),
http://git-wip-us.apache.org/repos/asf/camel/blob/89635686/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index 4979254..c6b938d 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -26,6 +26,7 @@ import javax.xml.bind.Binder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
+import org.apache.camel.model.HystrixConfigurationDefinition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -138,10 +139,11 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
addBeanDefinitionParser("threadPool", CamelThreadPoolFactoryBean.class, true, true);
addBeanDefinitionParser("redeliveryPolicyProfile", CamelRedeliveryPolicyFactoryBean.class, true, true);
- // jmx agent, stream caching, and property placeholder cannot be used outside of the camel context
+ // jmx agent, stream caching, hystrix configuration and property placeholder cannot be used outside of the camel context
addBeanDefinitionParser("jmxAgent", CamelJMXAgentDefinition.class, false, false);
addBeanDefinitionParser("streamCaching", CamelStreamCachingStrategyDefinition.class, false, false);
addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false, false);
+ addBeanDefinitionParser("hystrixConfiguration", HystrixConfigurationDefinition.class, false, false);
// errorhandler could be the sub element of camelContext or defined outside camelContext
BeanDefinitionParser errorHandlerParser = new ErrorHandlerDefinitionParser();
[10/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/c89b23aa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c89b23aa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c89b23aa
Branch: refs/heads/master
Commit: c89b23aadcf226f41ce8e7d65bec53a998eaee28
Parents: 930d49a
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Apr 18 16:37:51 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/FallbackDefinition.java | 60 ++++++++++++
.../model/HystrixCircuitBreakerDefinition.java | 96 ++++++++++++++++++++
.../apache/camel/model/ProcessorDefinition.java | 11 +++
.../CircuitBreakerLoadBalancerDefinition.java | 2 +-
.../HystrixCircuitBreakerProcessor.java | 96 ++++++++++++++++++++
.../resources/org/apache/camel/model/jaxb.index | 2 +
.../processor/HystrixCircuitBreakerTest.java | 50 ++++++++++
7 files changed, 316 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/java/org/apache/camel/model/FallbackDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/FallbackDefinition.java b/camel-core/src/main/java/org/apache/camel/model/FallbackDefinition.java
new file mode 100644
index 0000000..301c6d1
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/FallbackDefinition.java
@@ -0,0 +1,60 @@
+/**
+ * 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.model;
+
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Processor;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.CollectionStringBuffer;
+
+/**
+ * Route to be executed when circuit breaker executes fallback
+ */
+@Metadata(label = "eip,routing,circuitbreaker")
+@XmlRootElement(name = "fallback")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class FallbackDefinition extends OutputDefinition<FallbackDefinition> {
+
+ public FallbackDefinition() {
+ }
+
+ @Override
+ public String toString() {
+ return "Fallback[" + getOutputs() + "]";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ return this.createChildProcessor(routeContext, false);
+ }
+
+ @Override
+ public String getLabel() {
+ CollectionStringBuffer buffer = new CollectionStringBuffer("fallback[");
+ List<ProcessorDefinition<?>> list = getOutputs();
+ for (ProcessorDefinition<?> type : list) {
+ buffer.append(type.getLabel());
+ }
+ buffer.append("]");
+ return buffer.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
new file mode 100644
index 0000000..c7b4cd4
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
@@ -0,0 +1,96 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Processor;
+import org.apache.camel.processor.HystrixCircuitBreakerProcessor;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+
+@Metadata(label = "eip,routing,circuitbreaker")
+@XmlRootElement(name = "hystrixCircuitBreaker")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HystrixCircuitBreakerDefinition extends OutputDefinition<HystrixCircuitBreakerDefinition> {
+
+ // TODO: we can rename to circuitBreaker and then deprecated the CB in the load balancer
+ // the trick is to avoid a clash in the generated xml schema
+ // so for know we call it hystrixCircuitBreaker
+
+ @XmlElement
+ private FallbackDefinition fallback;
+
+ public HystrixCircuitBreakerDefinition() {
+ }
+
+ @Override
+ public String toString() {
+ return "HystrixCircuitBreaker[" + getOutputs() + "]";
+ }
+
+ @Override
+ public String getLabel() {
+ return "hystrixCircuitBreaker";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ Processor children = this.createChildProcessor(routeContext, true);
+
+ Processor fallbackProcessor = null;
+ if (fallback != null) {
+ fallbackProcessor = createProcessor(routeContext, fallback);
+ }
+ return new HystrixCircuitBreakerProcessor(children, fallbackProcessor);
+ }
+
+ @Override
+ public void addOutput(ProcessorDefinition<?> output) {
+ if (fallback != null) {
+ fallback.addOutput(output);
+ } else {
+ super.addOutput(output);
+ }
+ }
+
+ @Override
+ public ProcessorDefinition<?> end() {
+ if (fallback != null) {
+ // end fallback as well
+ fallback.end();
+ }
+ return super.end();
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Sets the otherwise node
+ *
+ * @return the builder
+ */
+ public HystrixCircuitBreakerDefinition fallback() {
+ fallback = new FallbackDefinition();
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 1ba4bb5..aa82e88 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -1470,6 +1470,17 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
+ * Creates a Circuit Breaker EIP that is using Hystrix.
+ *
+ * @return the builder
+ */
+ public HystrixCircuitBreakerDefinition hystrixCircuitBreaker() {
+ HystrixCircuitBreakerDefinition answer = new HystrixCircuitBreakerDefinition();
+ addOutput(answer);
+ return answer;
+ }
+
+ /**
* <a href="http://camel.apache.org/load-balancer.html">Load Balancer EIP:</a>
* Creates a loadbalance
*
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/java/org/apache/camel/model/loadbalancer/CircuitBreakerLoadBalancerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/loadbalancer/CircuitBreakerLoadBalancerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/loadbalancer/CircuitBreakerLoadBalancerDefinition.java
index 963339e..75b0e26 100644
--- a/camel-core/src/main/java/org/apache/camel/model/loadbalancer/CircuitBreakerLoadBalancerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/loadbalancer/CircuitBreakerLoadBalancerDefinition.java
@@ -41,7 +41,7 @@ import org.apache.camel.util.ObjectHelper;
* timeout is reached. After this timeout is reached, if there is a new call, it will pass and if the result is
* success the Circuit Breaker will move to closed state, or to open state if there was an error.
*/
-@Metadata(label = "eip,routing,loadbalance")
+@Metadata(label = "eip,routing,loadbalance,circuitbreaker")
@XmlRootElement(name = "circuitBreaker")
@XmlAccessorType(XmlAccessType.FIELD)
public class CircuitBreakerLoadBalancerDefinition extends LoadBalancerDefinition {
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
new file mode 100644
index 0000000..79d5037
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
@@ -0,0 +1,96 @@
+/**
+ * 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.processor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.AsyncProcessorHelper;
+
+public class HystrixCircuitBreakerProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
+
+ private String id;
+ private final Processor processor;
+ private final Processor fallback;
+
+ public HystrixCircuitBreakerProcessor(Processor processor, Processor fallback) {
+ this.processor = processor;
+ this.fallback = fallback;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String getTraceLabel() {
+ return "hystrixCircuitBreaker";
+ }
+
+ @Override
+ public List<Processor> next() {
+ if (!hasNext()) {
+ return null;
+ }
+ List<Processor> answer = new ArrayList<Processor>();
+ answer.add(processor);
+ if (fallback != null) {
+ answer.add(fallback);
+ }
+ return answer;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ // TODO: use camel-hystrix to process this
+ callback.done(true);
+ return true;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // noop
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 0fb9ac1..6232753 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -27,9 +27,11 @@ DescriptionDefinition
DynamicRouterDefinition
EnrichDefinition
ExpressionSubElementDefinition
+FallbackDefinition
FilterDefinition
FinallyDefinition
FromDefinition
+HystrixCircuitBreakerDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/c89b23aa/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java b/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
new file mode 100644
index 0000000..a44ddd5
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class HystrixCircuitBreakerTest extends ContextTestSupport {
+
+ public void testHystrixCircuitBreaker() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrixCircuitBreaker()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+}
[09/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/ea917730
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea917730
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea917730
Branch: refs/heads/master
Commit: ea917730ed80ee34e877729eda34bc3751e81f09
Parents: ad18d61
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:17:00 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../model/HystrixCircuitBreakerDefinition.java | 105 -------------------
.../apache/camel/model/HystrixDefinition.java | 94 +++++++++++++++++
.../apache/camel/model/ProcessorDefinition.java | 10 +-
.../HystrixCircuitBreakerProcessor.java | 96 -----------------
.../resources/org/apache/camel/model/jaxb.index | 2 +-
.../processor/HystrixCircuitBreakerTest.java | 50 ---------
.../component/hystrix/HystrixProcessor.java | 5 +-
.../hystrix/HystrixProcessorCommand.java | 4 +-
.../hystrix/HystrixProcessorFactory.java | 9 +-
.../camel/model/HystrixCircuitBreakerDefinition | 18 ----
.../org/apache/camel/model/HystrixDefinition | 18 ++++
.../HystrixCircuitBreakerFallbackTest.java | 53 ----------
.../hystrix/HystrixCircuitBreakerOkTest.java | 53 ----------
.../hystrix/HystrixRouteFallbackTest.java | 53 ++++++++++
.../component/hystrix/HystrixRouteOkTest.java | 53 ++++++++++
15 files changed, 238 insertions(+), 385 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
deleted file mode 100644
index 3228596..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
+++ /dev/null
@@ -1,105 +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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.camel.Processor;
-import org.apache.camel.processor.HystrixCircuitBreakerProcessor;
-import org.apache.camel.spi.Metadata;
-import org.apache.camel.spi.RouteContext;
-
-@Metadata(label = "eip,routing,circuitbreaker")
-@XmlRootElement(name = "hystrixCircuitBreaker")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class HystrixCircuitBreakerDefinition extends OutputDefinition<HystrixCircuitBreakerDefinition> {
-
- // TODO: we can rename to circuitBreaker and then deprecated the CB in the load balancer
- // the trick is to avoid a clash in the generated xml schema
- // so for know we call it hystrixCircuitBreaker
-
- @XmlElement
- private FallbackDefinition fallback;
-
- public HystrixCircuitBreakerDefinition() {
- }
-
- @Override
- public String toString() {
- return "HystrixCircuitBreaker[" + getOutputs() + "]";
- }
-
- @Override
- public String getLabel() {
- return "hystrixCircuitBreaker";
- }
-
- @Override
- public Processor createProcessor(RouteContext routeContext) throws Exception {
- Processor children = this.createChildProcessor(routeContext, true);
-
- Processor fallbackProcessor = null;
- if (fallback != null) {
- fallbackProcessor = createProcessor(routeContext, fallback);
- }
- return new HystrixCircuitBreakerProcessor(children, fallbackProcessor);
- }
-
- @Override
- public void addOutput(ProcessorDefinition<?> output) {
- if (fallback != null) {
- fallback.addOutput(output);
- } else {
- super.addOutput(output);
- }
- }
-
- @Override
- public ProcessorDefinition<?> end() {
- if (fallback != null) {
- // end fallback as well
- fallback.end();
- }
- return super.end();
- }
-
- public FallbackDefinition getFallback() {
- return fallback;
- }
-
- public void setFallback(FallbackDefinition fallback) {
- this.fallback = fallback;
- }
-
- // Fluent API
- // -------------------------------------------------------------------------
-
- /**
- * Sets the otherwise node
- *
- * @return the builder
- */
- public HystrixCircuitBreakerDefinition fallback() {
- fallback = new FallbackDefinition();
- fallback.setParent(this);
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/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
new file mode 100644
index 0000000..054aa1c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixDefinition.java
@@ -0,0 +1,94 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Processor;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+
+@Metadata(label = "eip,routing,circuitbreaker")
+@XmlRootElement(name = "hystrix")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
+
+ @XmlElement
+ private FallbackDefinition fallback;
+
+ public HystrixDefinition() {
+ }
+
+ @Override
+ public String toString() {
+ return "Hystrix[" + getOutputs() + "]";
+ }
+
+ @Override
+ public String getLabel() {
+ return "hystrix";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ throw new IllegalStateException("Cannot find camel-hystrix on the classpath.");
+ }
+
+ @Override
+ public void addOutput(ProcessorDefinition<?> output) {
+ if (fallback != null) {
+ fallback.addOutput(output);
+ } else {
+ super.addOutput(output);
+ }
+ }
+
+ @Override
+ public ProcessorDefinition<?> end() {
+ if (fallback != null) {
+ // end fallback as well
+ fallback.end();
+ }
+ return super.end();
+ }
+
+ public FallbackDefinition getFallback() {
+ return fallback;
+ }
+
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Sets the otherwise node
+ *
+ * @return the builder
+ */
+ public HystrixDefinition fallback() {
+ fallback = new FallbackDefinition();
+ fallback.setParent(this);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 2cdfa02..2270ef3 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -287,7 +287,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
} else if (defn instanceof OnExceptionDefinition || ProcessorDefinitionHelper.isParentOfType(OnExceptionDefinition.class, defn, true)) {
log.trace("{} is part of OnException so no error handler is applied", defn);
// do not use error handler for onExceptions blocks as it will handle errors itself
- } else if (defn instanceof HystrixCircuitBreakerDefinition || ProcessorDefinitionHelper.isParentOfType(HystrixCircuitBreakerDefinition.class, defn, true)) {
+ } else if (defn instanceof HystrixDefinition || ProcessorDefinitionHelper.isParentOfType(HystrixDefinition.class, defn, true)) {
log.trace("{} is part of HystrixCircuitBreaker so no error handler is applied", defn);
// do not use error handler for hystrixCircuitBreaker blocks as it will handle errors itself
} else if (defn instanceof MulticastDefinition) {
@@ -1473,12 +1473,14 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
- * Creates a Circuit Breaker EIP that is using Hystrix.
+ * Creates a Hystrix Circuit Breaker EIP.
+ * <p/>
+ * This requires having camel-hystrix on the classpath.
*
* @return the builder
*/
- public HystrixCircuitBreakerDefinition hystrixCircuitBreaker() {
- HystrixCircuitBreakerDefinition answer = new HystrixCircuitBreakerDefinition();
+ public HystrixDefinition hystrix() {
+ HystrixDefinition answer = new HystrixDefinition();
addOutput(answer);
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
deleted file mode 100644
index 79d5037..0000000
--- a/camel-core/src/main/java/org/apache/camel/processor/HystrixCircuitBreakerProcessor.java
+++ /dev/null
@@ -1,96 +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.processor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.apache.camel.Navigate;
-import org.apache.camel.Processor;
-import org.apache.camel.spi.IdAware;
-import org.apache.camel.support.ServiceSupport;
-import org.apache.camel.util.AsyncProcessorHelper;
-
-public class HystrixCircuitBreakerProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
-
- private String id;
- private final Processor processor;
- private final Processor fallback;
-
- public HystrixCircuitBreakerProcessor(Processor processor, Processor fallback) {
- this.processor = processor;
- this.fallback = fallback;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public String getId() {
- return id;
- }
-
- @Override
- public String getTraceLabel() {
- return "hystrixCircuitBreaker";
- }
-
- @Override
- public List<Processor> next() {
- if (!hasNext()) {
- return null;
- }
- List<Processor> answer = new ArrayList<Processor>();
- answer.add(processor);
- if (fallback != null) {
- answer.add(fallback);
- }
- return answer;
- }
-
- @Override
- public boolean hasNext() {
- return true;
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- AsyncProcessorHelper.process(this, exchange);
- }
-
- @Override
- public boolean process(Exchange exchange, AsyncCallback callback) {
- // TODO: use camel-hystrix to process this
- callback.done(true);
- return true;
- }
-
- @Override
- protected void doStart() throws Exception {
- // noop
- }
-
- @Override
- protected void doStop() throws Exception {
- // noop
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 6232753..1d80346 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -31,7 +31,7 @@ FallbackDefinition
FilterDefinition
FinallyDefinition
FromDefinition
-HystrixCircuitBreakerDefinition
+HystrixDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java b/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
deleted file mode 100644
index a44ddd5..0000000
--- a/camel-core/src/test/java/org/apache/camel/processor/HystrixCircuitBreakerTest.java
+++ /dev/null
@@ -1,50 +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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-
-public class HystrixCircuitBreakerTest extends ContextTestSupport {
-
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 0a9f708..81b09e4 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -30,6 +30,9 @@ import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorConverterHelper;
import org.apache.camel.util.AsyncProcessorHelper;
+/**
+ * Implementation of the Hystrix EIP.
+ */
public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
private String id;
@@ -54,7 +57,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public String getTraceLabel() {
- return "hystrixCircuitBreaker";
+ return "hystrix";
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 39d64d1..66a8150 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -21,8 +21,10 @@ import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
+/**
+ * Hystrix Command for the Camel Hystrix EIP.
+ */
public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
private final Exchange exchange;
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
index 40b5eb0..5d4cf99 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
@@ -17,11 +17,14 @@
package org.apache.camel.component.hystrix;
import org.apache.camel.Processor;
-import org.apache.camel.model.HystrixCircuitBreakerDefinition;
+import org.apache.camel.model.HystrixDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
+/**
+ * To integrate camel-hystrix with the Camel routes using the Hystrix EIP.
+ */
public class HystrixProcessorFactory implements ProcessorFactory {
@Override
@@ -32,8 +35,8 @@ public class HystrixProcessorFactory implements ProcessorFactory {
@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
- if (definition instanceof HystrixCircuitBreakerDefinition) {
- HystrixCircuitBreakerDefinition cb = (HystrixCircuitBreakerDefinition) definition;
+ if (definition instanceof HystrixDefinition) {
+ HystrixDefinition cb = (HystrixDefinition) definition;
String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
// create the regular processor
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
deleted file mode 100644
index 0e00349..0000000
--- a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
+++ /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.component.hystrix.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
new file mode 100644
index 0000000..0e00349
--- /dev/null
+++ b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
@@ -0,0 +1,18 @@
+#
+# 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.component.hystrix.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
deleted file mode 100644
index 3c7e45a..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.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.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixCircuitBreakerFallbackTest extends CamelTestSupport {
-
- @Test
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
deleted file mode 100644
index b34c6c2..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.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.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixCircuitBreakerOkTest extends CamelTestSupport {
-
- @Test
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .transform().constant("Bye World");
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
new file mode 100644
index 0000000..43aa817
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixRouteFallbackTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea917730/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
new file mode 100644
index 0000000..d5a2d5c
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixRouteOkTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+}
[24/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/2e3745fb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e3745fb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e3745fb
Branch: refs/heads/master
Commit: 2e3745fb6468b0e9ac58121dd3844101ce740905
Parents: fcbebd7
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 14:21:37 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../org/apache/camel/impl/DefaultProcessorFactory.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2e3745fb/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
index 4e64942..f958435 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
@@ -23,6 +23,17 @@ import org.apache.camel.spi.FactoryFinder;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
+/**
+ * Default {@link ProcessorFactory} that supports using 3rd party Camel components to implement the EIP {@link Processor}.
+ * <p/>
+ * The component should use the {@link FactoryFinder} SPI to specify a file with the name of the EIP model in the
+ * directory of {@link #RESOURCE_PATH}. The file should contain a property with key <tt>class</tt> that refers
+ * to the name of the {@link ProcessorFactory} the Camel component implement, which gets called for creating
+ * the {@link Processor}s for the EIP.
+ * <p/>
+ * The Hystrix EIP is such an example where {@link org.apache.camel.model.HystrixDefinition} is implemented
+ * in the <tt>camel-hystrix</tt> component.
+ */
public class DefaultProcessorFactory implements ProcessorFactory {
public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/model/";
[21/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/4b67c6c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4b67c6c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4b67c6c4
Branch: refs/heads/master
Commit: 4b67c6c4bb753a95ae081d64b9bfb922c919a332
Parents: 2e3745f
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 14:59:14 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../processor/HystrixProcessorFactory.java | 189 ++++++++++---------
1 file changed, 97 insertions(+), 92 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4b67c6c4/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 bc1cca8..276275d 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
@@ -59,99 +59,15 @@ public class HystrixProcessorFactory implements ProcessorFactory {
HystrixThreadPoolProperties.Setter threadPool = HystrixThreadPoolProperties.Setter();
setter.andThreadPoolPropertiesDefaults(threadPool);
- // any custom configuration then override the setter
- if (cb.getHystrixConfiguration() != null || cb.getHystrixConfigurationRef() != null) {
+ // at first configure any shared options
+ if (cb.getHystrixConfigurationRef() != null) {
+ HystrixConfigurationDefinition config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+ configureHystrix(command, threadPool, config);
+ }
+ // then any local configured can override
+ if (cb.getHystrixConfiguration() != 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) {
- command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
- }
- if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
- command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
- }
- if (config.getCircuitBreakerForceClosed() != null) {
- command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
- }
- if (config.getCircuitBreakerForceOpen() != null) {
- command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
- }
- if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
- command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
- }
- if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
- command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
- }
- if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
- command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
- }
- if (config.getExecutionIsolationStrategy() != null) {
- command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
- }
- if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
- command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
- }
- if (config.getExecutionTimeoutInMilliseconds() != null) {
- command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
- }
- if (config.getExecutionTimeoutEnabled() != null) {
- command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
- }
- if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
- command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
- }
- if (config.getFallbackEnabled() != null) {
- command.withFallbackEnabled(config.getFallbackEnabled());
- }
- if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
- command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
- }
- if (config.getMetricsRollingPercentileBucketSize() != null) {
- command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
- }
- if (config.getMetricsRollingPercentileEnabled() != null) {
- command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
- }
- if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
- command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
- }
- if (config.getMetricsRollingPercentileWindowBuckets() != null) {
- command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
- }
- if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) {
- command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
- }
- if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
- command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
- }
- if (config.getRequestCacheEnabled() != null) {
- command.withRequestCacheEnabled(config.getRequestCacheEnabled());
- }
- if (config.getRequestLogEnabled() != null) {
- command.withRequestLogEnabled(config.getRequestLogEnabled());
- }
- // thread pool
- if (config.getCorePoolSize() != null) {
- threadPool.withCoreSize(config.getCorePoolSize());
- }
- if (config.getKeepAliveTime() != null) {
- threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
- }
- if (config.getMaxQueueSize() != null) {
- threadPool.withMaxQueueSize(config.getMaxQueueSize());
- }
- if (config.getQueueSizeRejectionThreshold() != null) {
- threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
- }
- if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
- threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
- }
- if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
- threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
- }
+ configureHystrix(command, threadPool, config);
}
return new HystrixProcessor(id, setter, processor, fallback);
@@ -159,4 +75,93 @@ public class HystrixProcessorFactory implements ProcessorFactory {
return null;
}
}
+
+ private void configureHystrix(HystrixCommandProperties.Setter command, HystrixThreadPoolProperties.Setter threadPool, HystrixConfigurationDefinition config) {
+ // command
+ if (config.getCircuitBreakerEnabled() != null) {
+ command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
+ }
+ if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
+ command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
+ }
+ if (config.getCircuitBreakerForceClosed() != null) {
+ command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
+ }
+ if (config.getCircuitBreakerForceOpen() != null) {
+ command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
+ }
+ if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
+ command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
+ }
+ if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
+ command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
+ }
+ if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getExecutionIsolationStrategy() != null) {
+ command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
+ }
+ if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
+ command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
+ }
+ if (config.getExecutionTimeoutInMilliseconds() != null) {
+ command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
+ }
+ if (config.getExecutionTimeoutEnabled() != null) {
+ command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
+ }
+ if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getFallbackEnabled() != null) {
+ command.withFallbackEnabled(config.getFallbackEnabled());
+ }
+ if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
+ command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileBucketSize() != null) {
+ command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
+ }
+ if (config.getMetricsRollingPercentileEnabled() != null) {
+ command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
+ }
+ if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
+ command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileWindowBuckets() != null) {
+ command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
+ }
+ if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) {
+ command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
+ command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
+ }
+ if (config.getRequestCacheEnabled() != null) {
+ command.withRequestCacheEnabled(config.getRequestCacheEnabled());
+ }
+ if (config.getRequestLogEnabled() != null) {
+ command.withRequestLogEnabled(config.getRequestLogEnabled());
+ }
+ // thread pool
+ if (config.getCorePoolSize() != null) {
+ threadPool.withCoreSize(config.getCorePoolSize());
+ }
+ if (config.getKeepAliveTime() != null) {
+ threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
+ }
+ if (config.getMaxQueueSize() != null) {
+ threadPool.withMaxQueueSize(config.getMaxQueueSize());
+ }
+ if (config.getQueueSizeRejectionThreshold() != null) {
+ threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
+ threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
+ threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
+ }
+ }
}
[17/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/425d124f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/425d124f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/425d124f
Branch: refs/heads/master
Commit: 425d124f73b2ca0a8c863a54832d92a4dfda11b7
Parents: d041f70
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Apr 18 18:11:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../model/HystrixCircuitBreakerDefinition.java | 9 ++
.../apache/camel/model/ProcessorDefinition.java | 3 +
.../hystrix/HystrixDummyProcessor.java | 28 -----
.../component/hystrix/HystrixProcessor.java | 107 +++++++++++++++++++
.../hystrix/HystrixProcessorCommand.java | 87 +++++++++++++++
.../hystrix/HystrixProcessorFactory.java | 18 +++-
.../hystrix/HystrixCircuitBreakerTest.java | 7 +-
7 files changed, 225 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
index c7b4cd4..3228596 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixCircuitBreakerDefinition.java
@@ -80,6 +80,14 @@ public class HystrixCircuitBreakerDefinition extends OutputDefinition<HystrixCir
return super.end();
}
+ public FallbackDefinition getFallback() {
+ return fallback;
+ }
+
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
// Fluent API
// -------------------------------------------------------------------------
@@ -90,6 +98,7 @@ public class HystrixCircuitBreakerDefinition extends OutputDefinition<HystrixCir
*/
public HystrixCircuitBreakerDefinition fallback() {
fallback = new FallbackDefinition();
+ fallback.setParent(this);
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index aa82e88..2cdfa02 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -287,6 +287,9 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
} else if (defn instanceof OnExceptionDefinition || ProcessorDefinitionHelper.isParentOfType(OnExceptionDefinition.class, defn, true)) {
log.trace("{} is part of OnException so no error handler is applied", defn);
// do not use error handler for onExceptions blocks as it will handle errors itself
+ } else if (defn instanceof HystrixCircuitBreakerDefinition || ProcessorDefinitionHelper.isParentOfType(HystrixCircuitBreakerDefinition.class, defn, true)) {
+ log.trace("{} is part of HystrixCircuitBreaker so no error handler is applied", defn);
+ // do not use error handler for hystrixCircuitBreaker blocks as it will handle errors itself
} else if (defn instanceof MulticastDefinition) {
// do not use error handler for multicast as it offers fine grained error handlers for its outputs
// however if share unit of work is enabled, we need to wrap an error handler on the multicast parent
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
deleted file mode 100644
index 48d52f5..0000000
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
+++ /dev/null
@@ -1,28 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-
-public class HystrixDummyProcessor implements Processor {
-
- @Override
- public void process(Exchange exchange) throws Exception {
- System.out.println("Dummy processor");
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
new file mode 100644
index 0000000..6690234
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -0,0 +1,107 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.AsyncProcessorConverterHelper;
+import org.apache.camel.util.AsyncProcessorHelper;
+
+public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
+
+ private String id;
+ private final AsyncProcessor processor;
+ private final AsyncProcessor fallback;
+
+ public HystrixProcessor(String id, Processor processor, Processor fallback) {
+ this.id = id;
+ this.processor = AsyncProcessorConverterHelper.convert(processor);
+ this.fallback = AsyncProcessorConverterHelper.convert(fallback);
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getTraceLabel() {
+ return "hystrixCircuitBreaker";
+ }
+
+ @Override
+ public List<Processor> next() {
+ if (!hasNext()) {
+ return null;
+ }
+ List<Processor> answer = new ArrayList<Processor>();
+ answer.add(processor);
+ if (fallback != null) {
+ answer.add(fallback);
+ }
+ return answer;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
+
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
+ try {
+ command.execute();
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
+
+ callback.done(true);
+ return true;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // noop
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
new file mode 100644
index 0000000..39d64d1
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -0,0 +1,87 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
+
+ private final Exchange exchange;
+ private final AsyncCallback callback;
+ private final AsyncProcessor processor;
+ private final AsyncProcessor fallback;
+
+ public HystrixProcessorCommand(HystrixCommandGroupKey group, Exchange exchange, AsyncCallback callback,
+ AsyncProcessor processor, AsyncProcessor fallback) {
+ super(group);
+ this.exchange = exchange;
+ this.callback = callback;
+ this.processor = processor;
+ this.fallback = fallback;
+ }
+
+ @Override
+ protected Exchange getFallback() {
+ if (fallback != null) {
+ try {
+ Exception e = exchange.getException();
+ // store the last to endpoint as the failure endpoint
+ if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
+ exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
+ }
+ // give the rest of the pipeline another chance
+ exchange.setProperty(Exchange.EXCEPTION_HANDLED, true);
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
+ exchange.setException(null);
+ // and we should not be regarded as exhausted as we are in a try .. catch block
+ exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
+
+ fallback.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ } finally {
+ callback.done(true);
+ }
+ return exchange;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected Exchange run() throws Exception {
+ try {
+ processor.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ } finally {
+ callback.done(true);
+ }
+
+ // if we failed then throw an exception
+ if (exchange.getException() != null) {
+ throw exchange.getException();
+ }
+
+ return exchange;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
index c0924b1..40b5eb0 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.hystrix;
import org.apache.camel.Processor;
+import org.apache.camel.model.HystrixCircuitBreakerDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
@@ -25,11 +26,26 @@ public class HystrixProcessorFactory implements ProcessorFactory {
@Override
public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
+ // not in use
return null;
}
@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
- return new HystrixDummyProcessor();
+ if (definition instanceof HystrixCircuitBreakerDefinition) {
+ HystrixCircuitBreakerDefinition cb = (HystrixCircuitBreakerDefinition) definition;
+ String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
+
+ // create the regular processor
+ Processor processor = cb.createChildProcessor(routeContext, true);
+ Processor fallback = null;
+ if (cb.getFallback() != null) {
+ fallback = cb.getFallback().createProcessor(routeContext);
+ }
+
+ return new HystrixProcessor(id, processor, fallback);
+ } else {
+ return null;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/425d124f/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
index d714435..f4c035d 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
@@ -24,7 +24,7 @@ public class HystrixCircuitBreakerTest extends CamelTestSupport {
@Test
public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
template.sendBody("direct:start", "Hello World");
@@ -38,14 +38,11 @@ public class HystrixCircuitBreakerTest extends CamelTestSupport {
public void configure() throws Exception {
from("direct:start")
.hystrixCircuitBreaker()
- .to("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"))
.fallback()
.transform().constant("Fallback message")
.end()
.to("mock:result");
-
- from("direct:foo")
- .throwException(new IllegalArgumentException("Forced"));
}
};
}
[19/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/6f751748
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6f751748
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6f751748
Branch: refs/heads/master
Commit: 6f75174856dcebb953663ea16d66f045fa7056e5
Parents: ea91773
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 08:42:07 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 37 +++++++++++---
.../hystrix/HystrixProcessorCommand.java | 50 ++++++++++++------
.../hystrix/HystrixRouteFallbackTest.java | 2 +-
.../camel/component/hystrix/TryCatchTest.java | 53 ++++++++++++++++++++
.../src/test/resources/log4j.properties | 2 +-
5 files changed, 121 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6f751748/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 81b09e4..495706f 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -88,18 +88,22 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
// run this as if we run inside try .. catch so there is no regular Camel error handler
exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
+ // use our callback that does some cleanup when done
+ AsyncCallback hystrixCallback = new HystrixAsyncCallback(exchange, callback);
+
HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, hystrixCallback, processor, fallback);
try {
- command.execute();
+ command.queue();
} catch (Throwable e) {
+ // error adding to queue, so set as error and we are done
exchange.setException(e);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ callback.done(true);
+ return true;
}
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
-
- callback.done(true);
- return true;
+ return false;
}
@Override
@@ -111,4 +115,25 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
protected void doStop() throws Exception {
// noop
}
+
+ private static final class HystrixAsyncCallback implements AsyncCallback {
+
+ private final Exchange exchange;
+ private final AsyncCallback delegate;
+
+ public HystrixAsyncCallback(Exchange exchange, AsyncCallback delegate) {
+ this.exchange = exchange;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void done(boolean doneSync) {
+ if (doneSync) {
+ return;
+ }
+ // we are only done when called with false
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ delegate.done(doneSync);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f751748/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 66a8150..299819e 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -21,12 +21,15 @@ import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Hystrix Command for the Camel Hystrix EIP.
*/
public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
+ private static final Logger LOG = LoggerFactory.getLogger(HystrixProcessorCommand.class);
private final Exchange exchange;
private final AsyncCallback callback;
private final AsyncProcessor processor;
@@ -43,46 +46,63 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
@Override
protected Exchange getFallback() {
- if (fallback != null) {
- try {
- Exception e = exchange.getException();
+ // only run fallback if there was an exception
+ Exception exception = exchange.getException();
+ if (exception == null) {
+ return exchange;
+ }
+
+ try {
+ if (fallback != null) {
// store the last to endpoint as the failure endpoint
if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
}
// give the rest of the pipeline another chance
exchange.setProperty(Exchange.EXCEPTION_HANDLED, true);
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
exchange.setException(null);
// and we should not be regarded as exhausted as we are in a try .. catch block
exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
-
- fallback.process(exchange, callback);
- } catch (Exception e) {
- exchange.setException(e);
- } finally {
- callback.done(true);
+ // run the fallback processor
+ try {
+ LOG.debug("Running fallback: {}", exchange);
+ fallback.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ }
}
- return exchange;
- } else {
- return null;
+ } finally {
+ LOG.debug("Running fallback: {} success", exchange);
+ callback.done(false);
}
+
+ return exchange;
}
@Override
protected Exchange run() throws Exception {
+ LOG.debug("Running processor: {}", exchange);
+
+ exchange.setProperty(Exchange.EXCEPTION_HANDLED, null);
+ exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
try {
processor.process(exchange, callback);
} catch (Exception e) {
exchange.setException(e);
- } finally {
- callback.done(true);
}
// if we failed then throw an exception
if (exchange.getException() != null) {
throw exchange.getException();
}
+ // no errors we are done
+ try {
+ LOG.debug("Running processor: {} success", exchange);
+ callback.done(false);
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
return exchange;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f751748/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
index 43aa817..dc7c766 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
@@ -44,7 +44,7 @@ public class HystrixRouteFallbackTest extends CamelTestSupport {
.end()
.to("mock:result");
- from("direct:foo")
+ from("direct:foo").errorHandler(noErrorHandler())
.throwException(new IllegalArgumentException("Forced"));
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/6f751748/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
new file mode 100644
index 0000000..089b3b8
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/TryCatchTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class TryCatchTest extends CamelTestSupport {
+
+ @Test
+ public void testTryCatch() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("direct:foo")
+ .doCatch(Exception.class)
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo").errorHandler(noErrorHandler())
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f751748/components/camel-hystrix/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/log4j.properties b/components/camel-hystrix/src/test/resources/log4j.properties
index be664b3..2d541ed 100644
--- a/components/camel-hystrix/src/test/resources/log4j.properties
+++ b/components/camel-hystrix/src/test/resources/log4j.properties
@@ -18,7 +18,7 @@
#
# The logging properties used for testing.
#
-log4j.rootLogger=DEBUG, file
+log4j.rootLogger=INFO, file
# uncomment the following to enable camel debugging
#log4j.logger.org.apache.camel.component.hystrix=DEBUG
[08/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/ad18d616
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ad18d616
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ad18d616
Branch: refs/heads/master
Commit: ad18d61688042c8b46de34518389fb902d4df73f
Parents: 425d124
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Apr 18 18:15:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 6 ++-
.../HystrixCircuitBreakerFallbackTest.java | 53 ++++++++++++++++++++
.../hystrix/HystrixCircuitBreakerOkTest.java | 53 ++++++++++++++++++++
.../hystrix/HystrixCircuitBreakerTest.java | 50 ------------------
4 files changed, 111 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ad18d616/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 6690234..0a9f708 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -82,8 +82,10 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
+ // run this as if we run inside try .. catch so there is no regular Camel error handler
+ exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
+ HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
try {
command.execute();
@@ -91,6 +93,8 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
exchange.setException(e);
}
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+
callback.done(true);
return true;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ad18d616/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
new file mode 100644
index 0000000..3c7e45a
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerFallbackTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixCircuitBreakerFallbackTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrixCircuitBreaker() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrixCircuitBreaker()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ad18d616/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
new file mode 100644
index 0000000..b34c6c2
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerOkTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixCircuitBreakerOkTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrixCircuitBreaker() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrixCircuitBreaker()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ad18d616/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
deleted file mode 100644
index f4c035d..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
+++ /dev/null
@@ -1,50 +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;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixCircuitBreakerTest extends CamelTestSupport {
-
- @Test
- public void testHystrixCircuitBreaker() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrixCircuitBreaker()
- .throwException(new IllegalArgumentException("Forced"))
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
- }
- };
- }
-
-}
[02/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/4f16c26a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4f16c26a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4f16c26a
Branch: refs/heads/hys
Commit: 4f16c26a7c534da945919cc93f3ed5bf5532af3b
Parents: e325750
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 16:07:29 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 16:07:29 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/HystrixDefinition.java | 58 ++++++++++++++------
.../hystrix/processor/HystrixProcessor.java | 7 ++-
.../processor/HystrixProcessorCommand.java | 20 ++++++-
.../processor/HystrixProcessorFactory.java | 11 +++-
4 files changed, 73 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4f16c26a/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 91a8367..fa91362 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
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RouteContext;
@@ -37,6 +38,8 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
@XmlElement
private HystrixConfigurationDefinition hystrixConfiguration;
+ @XmlElement
+ private ExpressionSubElementDefinition cacheKey;
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
@XmlElement
@@ -117,14 +120,6 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
// Getter/Setter
// -------------------------------------------------------------------------
- public FallbackDefinition getFallback() {
- return fallback;
- }
-
- public void setFallback(FallbackDefinition fallback) {
- this.fallback = fallback;
- }
-
public HystrixConfigurationDefinition getHystrixConfiguration() {
return hystrixConfiguration;
}
@@ -141,18 +136,25 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
this.hystrixConfigurationRef = hystrixConfigurationRef;
}
- // Fluent API
- // -------------------------------------------------------------------------
+ public ExpressionSubElementDefinition getCacheKey() {
+ return cacheKey;
+ }
- /**
- * Sets the fallback node
- */
- public HystrixDefinition fallback() {
- fallback = new FallbackDefinition();
- fallback.setParent(this);
- return this;
+ public void setCacheKey(ExpressionSubElementDefinition cacheKey) {
+ this.cacheKey = cacheKey;
+ }
+
+ public FallbackDefinition getFallback() {
+ return fallback;
}
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
/**
* Configures the Hystrix EIP
* <p/>
@@ -179,4 +181,26 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
return this;
}
+ /**
+ * Sets the expression to use for generating the cache key.
+ * <p/>
+ * Key to be used for request caching.
+ * By default this returns null which means "do not cache".
+ * To enable caching set an expression that returns a string key uniquely representing the state of a command instance.
+ * If multiple command instances in the same request scope match keys then only the first will be executed and all others returned from cache.
+ */
+ public HystrixDefinition cacheKey(Expression expression) {
+ setCacheKey(new ExpressionSubElementDefinition(expression));
+ return this;
+ }
+
+ /**
+ * Sets the fallback node
+ */
+ public HystrixDefinition fallback() {
+ fallback = new FallbackDefinition();
+ fallback.setParent(this);
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4f16c26a/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 bc54b82..8f836c0 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
@@ -23,6 +23,7 @@ import com.netflix.hystrix.HystrixCommand;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.apache.camel.Navigate;
import org.apache.camel.Processor;
import org.apache.camel.spi.IdAware;
@@ -39,12 +40,14 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
private final HystrixCommand.Setter setter;
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
+ private final Expression cacheKey;
- public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback) {
+ public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback, Expression cacheKey) {
this.id = id;
this.setter = setter;
this.processor = AsyncProcessorConverterHelper.convert(processor);
this.fallback = AsyncProcessorConverterHelper.convert(fallback);
+ this.cacheKey = cacheKey;
}
@Override
@@ -87,7 +90,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, callback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, callback, processor, fallback, cacheKey);
try {
command.queue();
} catch (Throwable e) {
http://git-wip-us.apache.org/repos/asf/camel/blob/4f16c26a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index acb8605..0ba6158 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -17,10 +17,10 @@
package org.apache.camel.component.hystrix.processor;
import com.netflix.hystrix.HystrixCommand;
-import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,13 +34,29 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
private final AsyncCallback callback;
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
+ private final Expression cacheKey;
- public HystrixProcessorCommand(Setter setter, Exchange exchange, AsyncCallback callback, AsyncProcessor processor, AsyncProcessor fallback) {
+ public HystrixProcessorCommand(Setter setter, Exchange exchange, AsyncCallback callback, AsyncProcessor processor, AsyncProcessor fallback, Expression cacheKey) {
super(setter);
this.exchange = exchange;
this.callback = callback;
this.processor = processor;
this.fallback = fallback;
+ this.cacheKey = cacheKey;
+ }
+
+ @Override
+ protected String getCacheKey() {
+ // TODO: require https://github.com/Netflix/Hystrix/wiki/How-To-Use#Caching
+ if (cacheKey != null) {
+ try {
+ return cacheKey.evaluate(exchange, String.class);
+ } catch (Throwable e) {
+ // ignore
+ LOG.debug("Error evaluating cache key. This exception is ignored.", e);
+ }
+ }
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/4f16c26a/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 276275d..1389438 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
@@ -20,6 +20,7 @@ import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolProperties;
+import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.HystrixDefinition;
@@ -45,7 +46,7 @@ public class HystrixProcessorFactory implements ProcessorFactory {
HystrixDefinition cb = (HystrixDefinition) definition;
String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
- // create the regular processor
+ // create the regular and fallback processors
Processor processor = cb.createChildProcessor(routeContext, true);
Processor fallback = null;
if (cb.getFallback() != null) {
@@ -70,7 +71,13 @@ public class HystrixProcessorFactory implements ProcessorFactory {
configureHystrix(command, threadPool, config);
}
- return new HystrixProcessor(id, setter, processor, fallback);
+ // optional cache-key from expression
+ Expression cacheKey = null;
+ if (cb.getCacheKey() != null) {
+ cacheKey = cb.getCacheKey().createExpression(routeContext);
+ }
+
+ return new HystrixProcessor(id, setter, processor, fallback, cacheKey);
} else {
return null;
}
[07/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/d041f703
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d041f703
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d041f703
Branch: refs/heads/master
Commit: d041f703005df98111420079e5fb223f127e8a08
Parents: c89b23a
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Apr 18 17:33:01 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../apache/camel/impl/DefaultCamelContext.java | 2 +-
.../camel/impl/DefaultProcessorFactory.java | 67 ++++++++++++++++++++
.../hystrix/HystrixDummyProcessor.java | 28 ++++++++
.../hystrix/HystrixProcessorFactory.java | 35 ++++++++++
.../camel/model/HystrixCircuitBreakerDefinition | 18 ++++++
.../hystrix/HystrixCircuitBreakerTest.java | 53 ++++++++++++++++
6 files changed, 202 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 654c7b9..d96d646 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -245,7 +245,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
private ServicePool<Endpoint, Producer> producerServicePool = new SharedProducerServicePool(100);
private ServicePool<Endpoint, PollingConsumer> pollingConsumerServicePool = new SharedPollingConsumerServicePool(100);
private NodeIdFactory nodeIdFactory = new DefaultNodeIdFactory();
- private ProcessorFactory processorFactory;
+ private ProcessorFactory processorFactory = new DefaultProcessorFactory();
private MessageHistoryFactory messageHistoryFactory = new DefaultMessageHistoryFactory();
private InterceptStrategy defaultTracer;
private InterceptStrategy defaultBacklogTracer;
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
new file mode 100644
index 0000000..078743d
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
@@ -0,0 +1,67 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.impl;
+
+import org.apache.camel.NoFactoryAvailableException;
+import org.apache.camel.Processor;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.RouteContext;
+
+public class DefaultProcessorFactory implements ProcessorFactory {
+
+ public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/model/";
+
+ @Override
+ public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
+ String name = definition.getClass().getSimpleName();
+ FactoryFinder finder = routeContext.getCamelContext().getFactoryFinder(RESOURCE_PATH);
+ try {
+ if (finder != null) {
+ Object object = finder.newInstance(name);
+ if (object != null && object instanceof ProcessorFactory) {
+ ProcessorFactory pc = (ProcessorFactory) object;
+ return pc.createChildProcessor(routeContext, definition, mandatory);
+ }
+ }
+ } catch (NoFactoryAvailableException e) {
+ // ignore there is no custom factory
+ }
+
+ return null;
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
+ String name = definition.getClass().getSimpleName();
+ FactoryFinder finder = routeContext.getCamelContext().getFactoryFinder(RESOURCE_PATH);
+ try {
+ if (finder != null) {
+ Object object = finder.newInstance(name);
+ if (object != null && object instanceof ProcessorFactory) {
+ ProcessorFactory pc = (ProcessorFactory) object;
+ return pc.createProcessor(routeContext, definition);
+ }
+ }
+ } catch (NoFactoryAvailableException e) {
+ // ignore there is no custom factory
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
new file mode 100644
index 0000000..48d52f5
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixDummyProcessor.java
@@ -0,0 +1,28 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class HystrixDummyProcessor implements Processor {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ System.out.println("Dummy processor");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
new file mode 100644
index 0000000..c0924b1
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
@@ -0,0 +1,35 @@
+/**
+ * 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;
+
+import org.apache.camel.Processor;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.RouteContext;
+
+public class HystrixProcessorFactory implements ProcessorFactory {
+
+ @Override
+ public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
+ return new HystrixDummyProcessor();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
new file mode 100644
index 0000000..0e00349
--- /dev/null
+++ b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixCircuitBreakerDefinition
@@ -0,0 +1,18 @@
+#
+# 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.component.hystrix.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/d041f703/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
new file mode 100644
index 0000000..d714435
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixCircuitBreakerTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HystrixCircuitBreakerTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrixCircuitBreaker() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrixCircuitBreaker()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
[05/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/f3bef400
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f3bef400
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f3bef400
Branch: refs/heads/master
Commit: f3bef40024071956f73132844d2755b5a9517fb7
Parents: 4b67c6c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 16:07:29 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/HystrixDefinition.java | 58 ++++++++++++++------
.../hystrix/processor/HystrixProcessor.java | 7 ++-
.../processor/HystrixProcessorCommand.java | 20 ++++++-
.../processor/HystrixProcessorFactory.java | 11 +++-
4 files changed, 73 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f3bef400/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 91a8367..fa91362 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
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RouteContext;
@@ -37,6 +38,8 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
@XmlElement
private HystrixConfigurationDefinition hystrixConfiguration;
+ @XmlElement
+ private ExpressionSubElementDefinition cacheKey;
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
@XmlElement
@@ -117,14 +120,6 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
// Getter/Setter
// -------------------------------------------------------------------------
- public FallbackDefinition getFallback() {
- return fallback;
- }
-
- public void setFallback(FallbackDefinition fallback) {
- this.fallback = fallback;
- }
-
public HystrixConfigurationDefinition getHystrixConfiguration() {
return hystrixConfiguration;
}
@@ -141,18 +136,25 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
this.hystrixConfigurationRef = hystrixConfigurationRef;
}
- // Fluent API
- // -------------------------------------------------------------------------
+ public ExpressionSubElementDefinition getCacheKey() {
+ return cacheKey;
+ }
- /**
- * Sets the fallback node
- */
- public HystrixDefinition fallback() {
- fallback = new FallbackDefinition();
- fallback.setParent(this);
- return this;
+ public void setCacheKey(ExpressionSubElementDefinition cacheKey) {
+ this.cacheKey = cacheKey;
+ }
+
+ public FallbackDefinition getFallback() {
+ return fallback;
}
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
/**
* Configures the Hystrix EIP
* <p/>
@@ -179,4 +181,26 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
return this;
}
+ /**
+ * Sets the expression to use for generating the cache key.
+ * <p/>
+ * Key to be used for request caching.
+ * By default this returns null which means "do not cache".
+ * To enable caching set an expression that returns a string key uniquely representing the state of a command instance.
+ * If multiple command instances in the same request scope match keys then only the first will be executed and all others returned from cache.
+ */
+ public HystrixDefinition cacheKey(Expression expression) {
+ setCacheKey(new ExpressionSubElementDefinition(expression));
+ return this;
+ }
+
+ /**
+ * Sets the fallback node
+ */
+ public HystrixDefinition fallback() {
+ fallback = new FallbackDefinition();
+ fallback.setParent(this);
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3bef400/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 bc54b82..8f836c0 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
@@ -23,6 +23,7 @@ import com.netflix.hystrix.HystrixCommand;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.apache.camel.Navigate;
import org.apache.camel.Processor;
import org.apache.camel.spi.IdAware;
@@ -39,12 +40,14 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
private final HystrixCommand.Setter setter;
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
+ private final Expression cacheKey;
- public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback) {
+ public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback, Expression cacheKey) {
this.id = id;
this.setter = setter;
this.processor = AsyncProcessorConverterHelper.convert(processor);
this.fallback = AsyncProcessorConverterHelper.convert(fallback);
+ this.cacheKey = cacheKey;
}
@Override
@@ -87,7 +90,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, callback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, callback, processor, fallback, cacheKey);
try {
command.queue();
} catch (Throwable e) {
http://git-wip-us.apache.org/repos/asf/camel/blob/f3bef400/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index acb8605..0ba6158 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -17,10 +17,10 @@
package org.apache.camel.component.hystrix.processor;
import com.netflix.hystrix.HystrixCommand;
-import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,13 +34,29 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
private final AsyncCallback callback;
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
+ private final Expression cacheKey;
- public HystrixProcessorCommand(Setter setter, Exchange exchange, AsyncCallback callback, AsyncProcessor processor, AsyncProcessor fallback) {
+ public HystrixProcessorCommand(Setter setter, Exchange exchange, AsyncCallback callback, AsyncProcessor processor, AsyncProcessor fallback, Expression cacheKey) {
super(setter);
this.exchange = exchange;
this.callback = callback;
this.processor = processor;
this.fallback = fallback;
+ this.cacheKey = cacheKey;
+ }
+
+ @Override
+ protected String getCacheKey() {
+ // TODO: require https://github.com/Netflix/Hystrix/wiki/How-To-Use#Caching
+ if (cacheKey != null) {
+ try {
+ return cacheKey.evaluate(exchange, String.class);
+ } catch (Throwable e) {
+ // ignore
+ LOG.debug("Error evaluating cache key. This exception is ignored.", e);
+ }
+ }
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/f3bef400/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 276275d..1389438 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
@@ -20,6 +20,7 @@ import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixThreadPoolProperties;
+import org.apache.camel.Expression;
import org.apache.camel.Processor;
import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.HystrixDefinition;
@@ -45,7 +46,7 @@ public class HystrixProcessorFactory implements ProcessorFactory {
HystrixDefinition cb = (HystrixDefinition) definition;
String id = cb.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
- // create the regular processor
+ // create the regular and fallback processors
Processor processor = cb.createChildProcessor(routeContext, true);
Processor fallback = null;
if (cb.getFallback() != null) {
@@ -70,7 +71,13 @@ public class HystrixProcessorFactory implements ProcessorFactory {
configureHystrix(command, threadPool, config);
}
- return new HystrixProcessor(id, setter, processor, fallback);
+ // optional cache-key from expression
+ Expression cacheKey = null;
+ if (cb.getCacheKey() != null) {
+ cacheKey = cb.getCacheKey().createExpression(routeContext);
+ }
+
+ return new HystrixProcessor(id, setter, processor, fallback, cacheKey);
} else {
return null;
}
[13/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/a6369c6c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a6369c6c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a6369c6c
Branch: refs/heads/master
Commit: a6369c6cb80a9518f8e391116d520881ef798ada
Parents: 3dd001e
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 13:21:31 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/model/HystrixDefinition.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a6369c6c/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 171da30..734b913 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
@@ -32,7 +32,7 @@ import org.apache.camel.spi.RouteContext;
@Metadata(label = "eip,routing,circuitbreaker")
@XmlRootElement(name = "hystrix")
@XmlAccessorType(XmlAccessType.FIELD)
-public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
+public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
@XmlElement
private HystrixConfigurationDefinition hystrixConfiguration;
[03/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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());
}
[18/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/fcbebd77
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fcbebd77
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fcbebd77
Branch: refs/heads/master
Commit: fcbebd775b556fd08cd396e6c8f7e2a6f2dcc9ed
Parents: 8963568
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 14:17:21 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/impl/DefaultProcessorFactory.java | 6 +++---
.../apache/camel/model/HystrixConfigurationDefinition.java | 6 +++---
.../main/java/org/apache/camel/model/HystrixDefinition.java | 8 ++++----
.../apache/camel/component/hystrix/HystrixConfiguration.java | 6 +++---
.../camel/component/hystrix/processor/HystrixProcessor.java | 6 +++---
.../component/hystrix/processor/HystrixProcessorCommand.java | 6 +++---
6 files changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
index 078743d..4e64942 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultProcessorFactory.java
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
index c20d3ce..a47b347 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/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 146ddbe..91a8367 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
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
@@ -38,7 +38,7 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
@XmlElement
private HystrixConfigurationDefinition hystrixConfiguration;
@XmlElementRef
- protected List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
+ private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
@XmlElement
private FallbackDefinition fallback;
@XmlAttribute
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConfiguration.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConfiguration.java
index a8b1820..6fb62d1 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConfiguration.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConfiguration.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/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 3400af8..bc54b82 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
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/fcbebd77/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index 4af9377..acb8605 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
[06/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/3dd001e4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3dd001e4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3dd001e4
Branch: refs/heads/master
Commit: 3dd001e4d3112b6cf19dffe74342a48a568b917c
Parents: ca54a54
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 13:13:48 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../model/HystrixConfigurationDefinition.java | 641 +++++++++++++++++++
.../apache/camel/model/HystrixDefinition.java | 65 +-
.../resources/org/apache/camel/model/jaxb.index | 1 +
.../hystrix/processor/HystrixProcessor.java | 9 +-
.../processor/HystrixProcessorCommand.java | 5 +-
.../processor/HystrixProcessorFactory.java | 106 ++-
6 files changed, 808 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
new file mode 100644
index 0000000..5ea084e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
@@ -0,0 +1,641 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.model;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "eip,routing,circuitbreaker")
+@XmlRootElement(name = "hystrixConfiguration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HystrixConfigurationDefinition {
+
+ @XmlTransient
+ private HystrixDefinition parent;
+
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean circuitBreakerEnabled;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "50")
+ private Integer circuitBreakerErrorThresholdPercentage;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean circuitBreakerForceClosed;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "false")
+ private Boolean circuitBreakerForceOpen;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "20")
+ private Integer circuitBreakerRequestVolumeThreshold;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "5000")
+ private Integer circuitBreakerSleepWindowInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "20")
+ private Integer executionIsolationSemaphoreMaxConcurrentRequests;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "THREAD")
+ private String executionIsolationStrategy;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean executionIsolationThreadInterruptOnTimeout;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "1000")
+ private Integer executionTimeoutInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean executionTimeoutEnabled;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "10")
+ private Integer fallbackIsolationSemaphoreMaxConcurrentRequests;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean fallbackEnabled;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "500")
+ private Integer metricsHealthSnapshotIntervalInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "10")
+ private Integer metricsRollingPercentileBucketSize;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean metricsRollingPercentileEnabled;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "false")
+ private Integer metricsRollingPercentileWindowInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "6")
+ private Integer metricsRollingPercentileWindowBuckets;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "10000")
+ private Integer metricsRollingStatisticalWindowInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "10")
+ private Integer metricsRollingStatisticalWindowBuckets;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean requestCacheEnabled;
+ @XmlAttribute
+ @Metadata(label = "command", defaultValue = "true")
+ private Boolean requestLogEnabled;
+
+ // thread-pool
+
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "10")
+ private Integer corePoolSize;
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "1")
+ private Integer keepAliveTime;
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "-1")
+ private Integer maxQueueSize;
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "5")
+ private Integer queueSizeRejectionThreshold;
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "10000")
+ private Integer threadPoolRollingNumberStatisticalWindowInMilliseconds;
+ @XmlAttribute
+ @Metadata(label = "threadpool", defaultValue = "10")
+ private Integer threadPoolRollingNumberStatisticalWindowBuckets;
+
+ public HystrixConfigurationDefinition() {
+ }
+
+ public HystrixConfigurationDefinition(HystrixDefinition parent) {
+ this.parent = parent;
+ }
+
+ // Getter/Setter
+ // -------------------------------------------------------------------------
+
+ public Boolean getCircuitBreakerEnabled() {
+ return circuitBreakerEnabled;
+ }
+
+ public void setCircuitBreakerEnabled(Boolean circuitBreakerEnabled) {
+ this.circuitBreakerEnabled = circuitBreakerEnabled;
+ }
+
+ public Integer getCircuitBreakerErrorThresholdPercentage() {
+ return circuitBreakerErrorThresholdPercentage;
+ }
+
+ public void setCircuitBreakerErrorThresholdPercentage(Integer circuitBreakerErrorThresholdPercentage) {
+ this.circuitBreakerErrorThresholdPercentage = circuitBreakerErrorThresholdPercentage;
+ }
+
+ public Boolean getCircuitBreakerForceClosed() {
+ return circuitBreakerForceClosed;
+ }
+
+ public void setCircuitBreakerForceClosed(Boolean circuitBreakerForceClosed) {
+ this.circuitBreakerForceClosed = circuitBreakerForceClosed;
+ }
+
+ public Boolean getCircuitBreakerForceOpen() {
+ return circuitBreakerForceOpen;
+ }
+
+ public void setCircuitBreakerForceOpen(Boolean circuitBreakerForceOpen) {
+ this.circuitBreakerForceOpen = circuitBreakerForceOpen;
+ }
+
+ public Integer getCircuitBreakerRequestVolumeThreshold() {
+ return circuitBreakerRequestVolumeThreshold;
+ }
+
+ public void setCircuitBreakerRequestVolumeThreshold(Integer circuitBreakerRequestVolumeThreshold) {
+ this.circuitBreakerRequestVolumeThreshold = circuitBreakerRequestVolumeThreshold;
+ }
+
+ public Integer getCircuitBreakerSleepWindowInMilliseconds() {
+ return circuitBreakerSleepWindowInMilliseconds;
+ }
+
+ public void setCircuitBreakerSleepWindowInMilliseconds(Integer circuitBreakerSleepWindowInMilliseconds) {
+ this.circuitBreakerSleepWindowInMilliseconds = circuitBreakerSleepWindowInMilliseconds;
+ }
+
+ public Integer getExecutionIsolationSemaphoreMaxConcurrentRequests() {
+ return executionIsolationSemaphoreMaxConcurrentRequests;
+ }
+
+ public void setExecutionIsolationSemaphoreMaxConcurrentRequests(Integer executionIsolationSemaphoreMaxConcurrentRequests) {
+ this.executionIsolationSemaphoreMaxConcurrentRequests = executionIsolationSemaphoreMaxConcurrentRequests;
+ }
+
+ public String getExecutionIsolationStrategy() {
+ return executionIsolationStrategy;
+ }
+
+ public void setExecutionIsolationStrategy(String executionIsolationStrategy) {
+ this.executionIsolationStrategy = executionIsolationStrategy;
+ }
+
+ public Boolean getExecutionIsolationThreadInterruptOnTimeout() {
+ return executionIsolationThreadInterruptOnTimeout;
+ }
+
+ public void setExecutionIsolationThreadInterruptOnTimeout(Boolean executionIsolationThreadInterruptOnTimeout) {
+ this.executionIsolationThreadInterruptOnTimeout = executionIsolationThreadInterruptOnTimeout;
+ }
+
+ public Integer getExecutionTimeoutInMilliseconds() {
+ return executionTimeoutInMilliseconds;
+ }
+
+ public void setExecutionTimeoutInMilliseconds(Integer executionTimeoutInMilliseconds) {
+ this.executionTimeoutInMilliseconds = executionTimeoutInMilliseconds;
+ }
+
+ public Boolean getExecutionTimeoutEnabled() {
+ return executionTimeoutEnabled;
+ }
+
+ public void setExecutionTimeoutEnabled(Boolean executionTimeoutEnabled) {
+ this.executionTimeoutEnabled = executionTimeoutEnabled;
+ }
+
+ public Integer getFallbackIsolationSemaphoreMaxConcurrentRequests() {
+ return fallbackIsolationSemaphoreMaxConcurrentRequests;
+ }
+
+ public void setFallbackIsolationSemaphoreMaxConcurrentRequests(Integer fallbackIsolationSemaphoreMaxConcurrentRequests) {
+ this.fallbackIsolationSemaphoreMaxConcurrentRequests = fallbackIsolationSemaphoreMaxConcurrentRequests;
+ }
+
+ public Boolean getFallbackEnabled() {
+ return fallbackEnabled;
+ }
+
+ public void setFallbackEnabled(Boolean fallbackEnabled) {
+ this.fallbackEnabled = fallbackEnabled;
+ }
+
+ public Integer getMetricsHealthSnapshotIntervalInMilliseconds() {
+ return metricsHealthSnapshotIntervalInMilliseconds;
+ }
+
+ public void setMetricsHealthSnapshotIntervalInMilliseconds(Integer metricsHealthSnapshotIntervalInMilliseconds) {
+ this.metricsHealthSnapshotIntervalInMilliseconds = metricsHealthSnapshotIntervalInMilliseconds;
+ }
+
+ public Integer getMetricsRollingPercentileBucketSize() {
+ return metricsRollingPercentileBucketSize;
+ }
+
+ public void setMetricsRollingPercentileBucketSize(Integer metricsRollingPercentileBucketSize) {
+ this.metricsRollingPercentileBucketSize = metricsRollingPercentileBucketSize;
+ }
+
+ public Boolean getMetricsRollingPercentileEnabled() {
+ return metricsRollingPercentileEnabled;
+ }
+
+ public void setMetricsRollingPercentileEnabled(Boolean metricsRollingPercentileEnabled) {
+ this.metricsRollingPercentileEnabled = metricsRollingPercentileEnabled;
+ }
+
+ public Integer getMetricsRollingPercentileWindowInMilliseconds() {
+ return metricsRollingPercentileWindowInMilliseconds;
+ }
+
+ public void setMetricsRollingPercentileWindowInMilliseconds(Integer metricsRollingPercentileWindowInMilliseconds) {
+ this.metricsRollingPercentileWindowInMilliseconds = metricsRollingPercentileWindowInMilliseconds;
+ }
+
+ public Integer getMetricsRollingPercentileWindowBuckets() {
+ return metricsRollingPercentileWindowBuckets;
+ }
+
+ public void setMetricsRollingPercentileWindowBuckets(Integer metricsRollingPercentileWindowBuckets) {
+ this.metricsRollingPercentileWindowBuckets = metricsRollingPercentileWindowBuckets;
+ }
+
+ public Integer getMetricsRollingStatisticalWindowInMilliseconds() {
+ return metricsRollingStatisticalWindowInMilliseconds;
+ }
+
+ public void setMetricsRollingStatisticalWindowInMilliseconds(Integer metricsRollingStatisticalWindowInMilliseconds) {
+ this.metricsRollingStatisticalWindowInMilliseconds = metricsRollingStatisticalWindowInMilliseconds;
+ }
+
+ public Integer getMetricsRollingStatisticalWindowBuckets() {
+ return metricsRollingStatisticalWindowBuckets;
+ }
+
+ public void setMetricsRollingStatisticalWindowBuckets(Integer metricsRollingStatisticalWindowBuckets) {
+ this.metricsRollingStatisticalWindowBuckets = metricsRollingStatisticalWindowBuckets;
+ }
+
+ public Boolean getRequestCacheEnabled() {
+ return requestCacheEnabled;
+ }
+
+ public void setRequestCacheEnabled(Boolean requestCacheEnabled) {
+ this.requestCacheEnabled = requestCacheEnabled;
+ }
+
+ public Boolean getRequestLogEnabled() {
+ return requestLogEnabled;
+ }
+
+ public void setRequestLogEnabled(Boolean requestLogEnabled) {
+ this.requestLogEnabled = requestLogEnabled;
+ }
+
+ public Integer getCorePoolSize() {
+ return corePoolSize;
+ }
+
+ public void setCorePoolSize(Integer corePoolSize) {
+ this.corePoolSize = corePoolSize;
+ }
+
+ public Integer getKeepAliveTime() {
+ return keepAliveTime;
+ }
+
+ public void setKeepAliveTime(Integer keepAliveTime) {
+ this.keepAliveTime = keepAliveTime;
+ }
+
+ public Integer getMaxQueueSize() {
+ return maxQueueSize;
+ }
+
+ public void setMaxQueueSize(Integer maxQueueSize) {
+ this.maxQueueSize = maxQueueSize;
+ }
+
+ public Integer getQueueSizeRejectionThreshold() {
+ return queueSizeRejectionThreshold;
+ }
+
+ public void setQueueSizeRejectionThreshold(Integer queueSizeRejectionThreshold) {
+ this.queueSizeRejectionThreshold = queueSizeRejectionThreshold;
+ }
+
+ public Integer getThreadPoolRollingNumberStatisticalWindowInMilliseconds() {
+ return threadPoolRollingNumberStatisticalWindowInMilliseconds;
+ }
+
+ public void setThreadPoolRollingNumberStatisticalWindowInMilliseconds(Integer threadPoolRollingNumberStatisticalWindowInMilliseconds) {
+ this.threadPoolRollingNumberStatisticalWindowInMilliseconds = threadPoolRollingNumberStatisticalWindowInMilliseconds;
+ }
+
+ public Integer getThreadPoolRollingNumberStatisticalWindowBuckets() {
+ return threadPoolRollingNumberStatisticalWindowBuckets;
+ }
+
+ public void setThreadPoolRollingNumberStatisticalWindowBuckets(Integer threadPoolRollingNumberStatisticalWindowBuckets) {
+ this.threadPoolRollingNumberStatisticalWindowBuckets = threadPoolRollingNumberStatisticalWindowBuckets;
+ }
+
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted.
+ * <p>
+ * This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it
+ * should be open/closed, this property results in not even instantiating a circuit-breaker.
+ */
+ public HystrixConfigurationDefinition circuitBreakerEnabled(Boolean circuitBreakerEnabled) {
+ this.circuitBreakerEnabled = circuitBreakerEnabled;
+ return this;
+ }
+
+ /**
+ * Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests.
+ * <p>
+ * It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds;
+ * <p>
+ * The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().
+ */
+ public HystrixConfigurationDefinition circuitBreakerErrorThresholdPercentage(Integer circuitBreakerErrorThresholdPercentage) {
+ this.circuitBreakerErrorThresholdPercentage = circuitBreakerErrorThresholdPercentage;
+ return this;
+ }
+
+ /**
+ * If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of
+ * the error percentage from HystrixCommandMetrics.getHealthCounts().
+ * <p>
+ * The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.
+ */
+ public HystrixConfigurationDefinition circuitBreakerForceClosed(Boolean circuitBreakerForceClosed) {
+ this.circuitBreakerForceClosed = circuitBreakerForceClosed;
+ return this;
+ }
+
+ /**
+ * If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests.
+ * <p>
+ * This property takes precedence over circuitBreakerForceClosed();
+ */
+ public HystrixConfigurationDefinition circuitBreakerForceOpen(Boolean circuitBreakerForceOpen) {
+ this.circuitBreakerForceOpen = circuitBreakerForceOpen;
+ return this;
+ }
+
+ /**
+ * Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip.
+ * <p>
+ * If below this number the circuit will not trip regardless of error percentage.
+ */
+ public HystrixConfigurationDefinition circuitBreakerRequestVolumeThreshold(Integer circuitBreakerRequestVolumeThreshold) {
+ this.circuitBreakerRequestVolumeThreshold = circuitBreakerRequestVolumeThreshold;
+ return this;
+ }
+
+ /**
+ * The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.
+ */
+ public HystrixConfigurationDefinition circuitBreakerSleepWindowInMilliseconds(Integer circuitBreakerSleepWindowInMilliseconds) {
+ this.circuitBreakerSleepWindowInMilliseconds = circuitBreakerSleepWindowInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected.
+ * <p>
+ * Applicable only when executionIsolationStrategy == SEMAPHORE.
+ */
+ public HystrixConfigurationDefinition executionIsolationSemaphoreMaxConcurrentRequests(Integer executionIsolationSemaphoreMaxConcurrentRequests) {
+ this.executionIsolationSemaphoreMaxConcurrentRequests = executionIsolationSemaphoreMaxConcurrentRequests;
+ return this;
+ }
+
+ /**
+ * What isolation strategy HystrixCommand.run() will be executed with.
+ * <p>
+ * If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool.
+ * <p>
+ * If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.
+ */
+ public HystrixConfigurationDefinition executionIsolationStrategy(String executionIsolationStrategy) {
+ this.executionIsolationStrategy = executionIsolationStrategy;
+ return this;
+ }
+
+ /**
+ * Whether the execution thread should attempt an interrupt (using {@link Future#cancel}) when a thread times out.
+ * <p>
+ * Applicable only when executionIsolationStrategy() == THREAD.
+ */
+ public HystrixConfigurationDefinition executionIsolationThreadInterruptOnTimeout(Boolean executionIsolationThreadInterruptOnTimeout) {
+ this.executionIsolationThreadInterruptOnTimeout = executionIsolationThreadInterruptOnTimeout;
+ return this;
+ }
+
+ /**
+ * Time in milliseconds at which point the command will timeout and halt execution.
+ * <p>
+ * If {@link #executionIsolationThreadInterruptOnTimeout} == true and the command is thread-isolated, the executing thread will be interrupted.
+ * If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.
+ */
+ public HystrixConfigurationDefinition executionTimeoutInMilliseconds(Integer executionTimeoutInMilliseconds) {
+ this.executionTimeoutInMilliseconds = executionTimeoutInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Whether the timeout mechanism is enabled for this command
+ */
+ public HystrixConfigurationDefinition executionTimeoutEnabled(Boolean executionTimeoutEnabled) {
+ this.executionTimeoutEnabled = executionTimeoutEnabled;
+ return this;
+ }
+
+ /**
+ * Number of concurrent requests permitted to HystrixCommand.getFallback().
+ * Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.
+ */
+ public HystrixConfigurationDefinition fallbackIsolationSemaphoreMaxConcurrentRequests(Integer fallbackIsolationSemaphoreMaxConcurrentRequests) {
+ this.fallbackIsolationSemaphoreMaxConcurrentRequests = fallbackIsolationSemaphoreMaxConcurrentRequests;
+ return this;
+ }
+
+ /**
+ * Whether HystrixCommand.getFallback() should be attempted when failure occurs.
+ */
+ public HystrixConfigurationDefinition fallbackEnabled(Boolean fallbackEnabled) {
+ this.fallbackEnabled = fallbackEnabled;
+ return this;
+ }
+
+ /**
+ * Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error
+ * percentages and affect HystrixCircuitBreaker.isOpen() status.
+ * <p>
+ * On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.
+ */
+ public HystrixConfigurationDefinition metricsHealthSnapshotIntervalInMilliseconds(Integer metricsHealthSnapshotIntervalInMilliseconds) {
+ this.metricsHealthSnapshotIntervalInMilliseconds = metricsHealthSnapshotIntervalInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Maximum number of values stored in each bucket of the rolling percentile.
+ * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingPercentileBucketSize(Integer metricsRollingPercentileBucketSize) {
+ this.metricsRollingPercentileBucketSize = metricsRollingPercentileBucketSize;
+ return this;
+ }
+
+ /**
+ * Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingPercentileEnabled(Boolean metricsRollingPercentileEnabled) {
+ this.metricsRollingPercentileEnabled = metricsRollingPercentileEnabled;
+ return this;
+ }
+
+ /**
+ * Duration of percentile rolling window in milliseconds.
+ * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingPercentileWindowInMilliseconds(Integer metricsRollingPercentileWindowInMilliseconds) {
+ this.metricsRollingPercentileWindowInMilliseconds = metricsRollingPercentileWindowInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Number of buckets the rolling percentile window is broken into.
+ * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingPercentileWindowBuckets(Integer metricsRollingPercentileWindowBuckets) {
+ this.metricsRollingPercentileWindowBuckets = metricsRollingPercentileWindowBuckets;
+ return this;
+ }
+
+ /**
+ * Duration of statistical rolling window in milliseconds.
+ * This is passed into HystrixRollingNumber inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingStatisticalWindowInMilliseconds(Integer metricsRollingStatisticalWindowInMilliseconds) {
+ this.metricsRollingStatisticalWindowInMilliseconds = metricsRollingStatisticalWindowInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Number of buckets the rolling statistical window is broken into.
+ * This is passed into HystrixRollingNumber inside HystrixCommandMetrics.
+ */
+ public HystrixConfigurationDefinition metricsRollingStatisticalWindowBuckets(Integer metricsRollingStatisticalWindowBuckets) {
+ this.metricsRollingStatisticalWindowBuckets = metricsRollingStatisticalWindowBuckets;
+ return this;
+ }
+
+ /**
+ * Whether HystrixCommand.getCacheKey() should be used with HystrixRequestCache
+ * to provide de-duplication functionality via request-scoped caching.
+ */
+ public HystrixConfigurationDefinition requestCacheEnabled(Boolean requestCacheEnabled) {
+ this.requestCacheEnabled = requestCacheEnabled;
+ return this;
+ }
+
+ /**
+ * Whether HystrixCommand execution and events should be logged to HystrixRequestLog.
+ */
+ public HystrixConfigurationDefinition requestLogEnabled(Boolean requestLogEnabled) {
+ this.requestLogEnabled = requestLogEnabled;
+ return this;
+ }
+
+ /**
+ * Core thread-pool size that gets passed to {@link java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int)}
+ */
+ public HystrixConfigurationDefinition corePoolSize(Integer corePoolSize) {
+ this.corePoolSize = corePoolSize;
+ return this;
+ }
+
+ /**
+ * Keep-alive time in minutes that gets passed to {@link ThreadPoolExecutor#setKeepAliveTime(long, TimeUnit)}
+ */
+ public HystrixConfigurationDefinition keepAliveTime(Integer keepAliveTime) {
+ this.keepAliveTime = keepAliveTime;
+ return this;
+ }
+
+ /**
+ * Max queue size that gets passed to {@link BlockingQueue} in HystrixConcurrencyStrategy.getBlockingQueue(int)
+ *
+ * This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly.
+ * For that, use queueSizeRejectionThreshold().
+ */
+ public HystrixConfigurationDefinition maxQueueSize(Integer maxQueueSize) {
+ this.maxQueueSize = maxQueueSize;
+ return this;
+ }
+
+ /**
+ * Queue size rejection threshold is an artificial "max" size at which rejections will occur even
+ * if {@link #maxQueueSize} has not been reached. This is done because the {@link #maxQueueSize}
+ * of a {@link BlockingQueue} can not be dynamically changed and we want to support dynamically
+ * changing the queue size that affects rejections.
+ * <p>
+ * This is used by HystrixCommand when queuing a thread for execution.
+ */
+ public HystrixConfigurationDefinition queueSizeRejectionThreshold(Integer queueSizeRejectionThreshold) {
+ this.queueSizeRejectionThreshold = queueSizeRejectionThreshold;
+ return this;
+ }
+
+ /**
+ * Duration of statistical rolling window in milliseconds.
+ * This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.
+ */
+ public HystrixConfigurationDefinition threadPoolRollingNumberStatisticalWindowInMilliseconds(Integer threadPoolRollingNumberStatisticalWindowInMilliseconds) {
+ this.threadPoolRollingNumberStatisticalWindowInMilliseconds = threadPoolRollingNumberStatisticalWindowInMilliseconds;
+ return this;
+ }
+
+ /**
+ * Number of buckets the rolling statistical window is broken into.
+ * This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.
+ */
+ public HystrixConfigurationDefinition threadPoolRollingNumberStatisticalWindowBuckets(Integer threadPoolRollingNumberStatisticalWindowBuckets) {
+ this.threadPoolRollingNumberStatisticalWindowBuckets = threadPoolRollingNumberStatisticalWindowBuckets;
+ return this;
+ }
+
+ /**
+ * End of configuration
+ */
+ public HystrixDefinition end() {
+ return parent;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/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 c8abd53..171da30 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
@@ -16,10 +16,13 @@
*/
package org.apache.camel.model;
+import java.util.ArrayList;
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.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.Processor;
@@ -32,6 +35,10 @@ import org.apache.camel.spi.RouteContext;
public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
@XmlElement
+ private HystrixConfigurationDefinition hystrixConfiguration;
+ @XmlElementRef
+ protected List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
+ @XmlElement
private FallbackDefinition fallback;
public HystrixDefinition() {
@@ -52,6 +59,23 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
throw new IllegalStateException("Cannot find camel-hystrix on the classpath.");
}
+ public List<ProcessorDefinition<?>> getOutputs() {
+ return outputs;
+ }
+
+ public boolean isOutputSupported() {
+ return true;
+ }
+
+ public void setOutputs(List<ProcessorDefinition<?>> outputs) {
+ this.outputs = outputs;
+ if (outputs != null) {
+ for (ProcessorDefinition<?> output : outputs) {
+ configureChild(output);
+ }
+ }
+ }
+
@Override
public void addOutput(ProcessorDefinition<?> output) {
if (output instanceof FallbackDefinition) {
@@ -74,14 +98,6 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
return super.end();
}
- public FallbackDefinition getFallback() {
- return fallback;
- }
-
- public void setFallback(FallbackDefinition fallback) {
- this.fallback = fallback;
- }
-
protected void preCreateProcessor() {
// move the fallback from outputs to fallback which we need to ensure
// such as when using the XML DSL
@@ -95,13 +111,30 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
}
}
+ // Getter/Setter
+ // -------------------------------------------------------------------------
+
+ public FallbackDefinition getFallback() {
+ return fallback;
+ }
+
+ public void setFallback(FallbackDefinition fallback) {
+ this.fallback = fallback;
+ }
+
+ public HystrixConfigurationDefinition getHystrixConfiguration() {
+ return hystrixConfiguration;
+ }
+
+ public void setHystrixConfiguration(HystrixConfigurationDefinition hystrixConfiguration) {
+ this.hystrixConfiguration = hystrixConfiguration;
+ }
+
// Fluent API
// -------------------------------------------------------------------------
/**
- * Sets the otherwise node
- *
- * @return the builder
+ * Sets the fallback node
*/
public HystrixDefinition fallback() {
fallback = new FallbackDefinition();
@@ -109,4 +142,14 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
return this;
}
+ /**
+ * Configures the Hystrix EIP
+ * <p/>
+ * Use <tt>end</tt> when configuration is complete, to return back to the Hystrix EIP.
+ */
+ public HystrixConfigurationDefinition configure() {
+ hystrixConfiguration = new HystrixConfigurationDefinition(this);
+ return hystrixConfiguration;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 1d80346..9315335 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -32,6 +32,7 @@ FilterDefinition
FinallyDefinition
FromDefinition
HystrixDefinition
+HystrixConfigurationDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/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 c3b272d..3400af8 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
@@ -19,7 +19,7 @@ package org.apache.camel.component.hystrix.processor;
import java.util.ArrayList;
import java.util.List;
-import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommand;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
@@ -36,11 +36,13 @@ import org.apache.camel.util.AsyncProcessorHelper;
public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
private String id;
+ private final HystrixCommand.Setter setter;
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
- public HystrixProcessor(String id, Processor processor, Processor fallback) {
+ public HystrixProcessor(String id, HystrixCommand.Setter setter, Processor processor, Processor fallback) {
this.id = id;
+ this.setter = setter;
this.processor = AsyncProcessorConverterHelper.convert(processor);
this.fallback = AsyncProcessorConverterHelper.convert(fallback);
}
@@ -85,8 +87,7 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, callback, processor, fallback);
try {
command.queue();
} catch (Throwable e) {
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index 16c0645..c728d6a 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -35,9 +35,8 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
private final AsyncProcessor processor;
private final AsyncProcessor fallback;
- public HystrixProcessorCommand(HystrixCommandGroupKey group, Exchange exchange, AsyncCallback callback,
- AsyncProcessor processor, AsyncProcessor fallback) {
- super(group);
+ public HystrixProcessorCommand(Setter setter, Exchange exchange, AsyncCallback callback, AsyncProcessor processor, AsyncProcessor fallback) {
+ super(setter);
this.exchange = exchange;
this.callback = callback;
this.processor = processor;
http://git-wip-us.apache.org/repos/asf/camel/blob/3dd001e4/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 b6d3a80..8e4a7f1 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
@@ -16,7 +16,12 @@
*/
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.HystrixThreadPoolProperties;
import org.apache.camel.Processor;
+import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.HystrixDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.spi.ProcessorFactory;
@@ -46,7 +51,106 @@ public class HystrixProcessorFactory implements ProcessorFactory {
fallback = cb.getFallback().createProcessor(routeContext);
}
- return new HystrixProcessor(id, processor, fallback);
+ // create setter using the default options
+ HystrixCommand.Setter setter = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id));
+ HystrixCommandProperties.Setter command = HystrixCommandProperties.Setter();
+ setter.andCommandPropertiesDefaults(command);
+ HystrixThreadPoolProperties.Setter threadPool = HystrixThreadPoolProperties.Setter();
+ setter.andThreadPoolPropertiesDefaults(threadPool);
+
+ // any custom configuration then override the setter
+ if (cb.getHystrixConfiguration() != null) {
+ HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+
+ // command
+ if (config.getCircuitBreakerEnabled() != null) {
+ command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
+ }
+ if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
+ command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
+ }
+ if (config.getCircuitBreakerForceClosed() != null) {
+ command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
+ }
+ if (config.getCircuitBreakerForceOpen() != null) {
+ command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
+ }
+ if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
+ command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
+ }
+ if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
+ command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
+ }
+ if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getExecutionIsolationStrategy() != null) {
+ command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
+ }
+ if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
+ command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
+ }
+ if (config.getExecutionTimeoutInMilliseconds() != null) {
+ command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
+ }
+ if (config.getExecutionTimeoutEnabled() != null) {
+ command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
+ }
+ if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
+ command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
+ }
+ if (config.getFallbackEnabled() != null) {
+ command.withFallbackEnabled(config.getFallbackEnabled());
+ }
+ if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
+ command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileBucketSize() != null) {
+ command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
+ }
+ if (config.getMetricsRollingPercentileEnabled() != null) {
+ command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
+ }
+ if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
+ command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingPercentileWindowBuckets() != null) {
+ command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
+ }
+ if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) {
+ command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
+ }
+ if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
+ command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
+ }
+ if (config.getRequestCacheEnabled() != null) {
+ command.withRequestCacheEnabled(config.getRequestCacheEnabled());
+ }
+ if (config.getRequestLogEnabled() != null) {
+ command.withRequestLogEnabled(config.getRequestLogEnabled());
+ }
+ // thread pool
+ if (config.getCorePoolSize() != null) {
+ threadPool.withCoreSize(config.getCorePoolSize());
+ }
+ if (config.getKeepAliveTime() != null) {
+ threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
+ }
+ if (config.getMaxQueueSize() != null) {
+ threadPool.withMaxQueueSize(config.getMaxQueueSize());
+ }
+ if (config.getQueueSizeRejectionThreshold() != null) {
+ threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
+ threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
+ }
+ if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
+ threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
+ }
+ }
+
+ return new HystrixProcessor(id, setter, processor, fallback);
} else {
return null;
}
[15/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/ca8f07c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ca8f07c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ca8f07c6
Branch: refs/heads/master
Commit: ca8f07c6995198938297d254eb13b7b02b9f2120
Parents: a6369c6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 13:32:32 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../processor/HystrixProcessorCommand.java | 9 ++-
.../HystrixRouteFallbackDisabledTest.java | 58 ++++++++++++++++++++
2 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ca8f07c6/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
index c728d6a..4af9377 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -93,11 +93,14 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
exchange.setException(e);
}
- // if we failed then throw an exception
- if (exchange.getException() != null) {
+ // is fallback enabled
+ Boolean fallbackEnabled = getProperties().fallbackEnabled().get();
+
+ // if we failed then throw an exception if fallback is enabled
+ if (fallbackEnabled == null || fallbackEnabled && exchange.getException() != null) {
throw exchange.getException();
}
- // no errors we are done
+ // no fallback then we are done
try {
LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
http://git-wip-us.apache.org/repos/asf/camel/blob/ca8f07c6/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
new file mode 100644
index 0000000..9e81ce9
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackDisabledTest.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.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"));
+ }
+ };
+ }
+
+}
[16/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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"));
- }
- };
- }
-
-}
[12/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/37d3315a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/37d3315a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/37d3315a
Branch: refs/heads/master
Commit: 37d3315affdc23862b2c9c5c608b205fced6e4c2
Parents: f180fbe
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 09:38:51 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/HystrixDefinition.java | 24 +++++-
components/camel-hystrix/pom.xml | 88 ++++++++++----------
.../hystrix/SpringHystrixRouteFallbackTest.java | 40 +++++++++
.../hystrix/SpringHystrixRouteOkTest.java | 40 +++++++++
.../hystrix/SpringHystrixRouteFallbackTest.xml | 44 ++++++++++
.../hystrix/SpringHystrixRouteOkTest.xml | 46 ++++++++++
6 files changed, 237 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/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 054aa1c..c8abd53 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.model;
+import java.util.Iterator;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -53,10 +54,14 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
@Override
public void addOutput(ProcessorDefinition<?> output) {
- if (fallback != null) {
- fallback.addOutput(output);
+ if (output instanceof FallbackDefinition) {
+ fallback = (FallbackDefinition) output;
} else {
- super.addOutput(output);
+ if (fallback != null) {
+ fallback.addOutput(output);
+ } else {
+ super.addOutput(output);
+ }
}
}
@@ -77,6 +82,19 @@ public class HystrixDefinition extends OutputDefinition<HystrixDefinition> {
this.fallback = fallback;
}
+ protected void preCreateProcessor() {
+ // move the fallback from outputs to fallback which we need to ensure
+ // such as when using the XML DSL
+ Iterator<ProcessorDefinition<?>> it = outputs.iterator();
+ while (it.hasNext()) {
+ ProcessorDefinition<?> out = it.next();
+ if (out instanceof FallbackDefinition) {
+ fallback = (FallbackDefinition) out;
+ it.remove();
+ }
+ }
+ }
+
// Fluent API
// -------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/components/camel-hystrix/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/pom.xml b/components/camel-hystrix/pom.xml
index 64ece05..72c38ab 100644
--- a/components/camel-hystrix/pom.xml
+++ b/components/camel-hystrix/pom.xml
@@ -15,46 +15,50 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.18-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-hystrix</artifactId>
- <packaging>jar</packaging>
- <name>Camel :: Hystrix</name>
- <description>Camel Hystrix support</description>
-
- <properties>
- <camel.osgi.export.pkg>org.apache.camel.component.hystrix.*</camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=hystrix</camel.osgi.export.service>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>com.netflix.hystrix</groupId>
- <artifactId>hystrix-core</artifactId>
- <version>${hystrix-version}</version>
- </dependency>
-
- <!-- for testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.18-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-hystrix</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Hystrix</name>
+ <description>Camel Hystrix support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.hystrix.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=hystrix</camel.osgi.export.service>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.netflix.hystrix</groupId>
+ <artifactId>hystrix-core</artifactId>
+ <version>${hystrix-version}</version>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java
new file mode 100644
index 0000000..263ab47
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.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.hystrix;
+
+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 SpringHystrixRouteFallbackTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java
new file mode 100644
index 0000000..f459a7f
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.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.hystrix;
+
+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 SpringHystrixRouteOkTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
new file mode 100644
index 0000000..441b8b6
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
@@ -0,0 +1,44 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <hystrix>
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <throwException exceptionType="java.lang.IllegalArgumentException" message="Forced"/>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/37d3315a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
new file mode 100644
index 0000000..26fdabc
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
@@ -0,0 +1,46 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <hystrix>
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
[04/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/f5b47783
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5b47783
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5b47783
Branch: refs/heads/hys
Commit: f5b47783d1be42e4b82c8a0532fe32bca6429910
Parents: ccb70f6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 16:38:59 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 16:38:59 2016 +0200
----------------------------------------------------------------------
.../model/HystrixConfigurationDefinition.java | 39 +++++++++++++++++++-
.../apache/camel/model/HystrixDefinition.java | 28 +-------------
.../processor/HystrixProcessorFactory.java | 37 +++++++++++++------
.../processor/HystrixRouteConfigTest.java | 2 +-
.../processor/SpringHystrixRouteConfigTest.xml | 2 +-
5 files changed, 67 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f5b47783/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
index a47b347..d4e9f52 100644
--- a/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/HystrixConfigurationDefinition.java
@@ -33,9 +33,14 @@ import org.apache.camel.spi.Metadata;
@XmlAccessorType(XmlAccessType.FIELD)
public class HystrixConfigurationDefinition extends IdentifiedType {
+ public static final String DEFAULT_GROUP_KEY = "CamelHystrix";
+
@XmlTransient
private HystrixDefinition parent;
-
+ @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+ private String groupKey;
+ @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
+ private String threadPoolKey;
@XmlAttribute
@Metadata(label = "command", defaultValue = "true")
private Boolean circuitBreakerEnabled;
@@ -134,6 +139,22 @@ public class HystrixConfigurationDefinition extends IdentifiedType {
// 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 Boolean getCircuitBreakerEnabled() {
return circuitBreakerEnabled;
}
@@ -363,6 +384,22 @@ public class HystrixConfigurationDefinition extends IdentifiedType {
// -------------------------------------------------------------------------
/**
+ * Sets the group key to use. The default value is CamelHystrix.
+ */
+ public HystrixConfigurationDefinition groupKey(String groupKey) {
+ setGroupKey(groupKey);
+ return this;
+ }
+
+ /**
+ * Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.
+ */
+ public HystrixConfigurationDefinition threadPoolKey(String threadPoolKey) {
+ setThreadPoolKey(threadPoolKey);
+ return this;
+ }
+
+ /**
* Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted.
* <p>
* This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it
http://git-wip-us.apache.org/repos/asf/camel/blob/f5b47783/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 b5fc6a8..3ca72f5 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,13 +36,6 @@ 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
@@ -127,23 +120,6 @@ 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;
}
@@ -183,7 +159,7 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
* Sets the group key to use. The default value is CamelHystrix.
*/
public HystrixDefinition groupKey(String groupKey) {
- setGroupKey(groupKey);
+ configure().groupKey(groupKey);
return this;
}
@@ -191,7 +167,7 @@ public class HystrixDefinition extends ProcessorDefinition<HystrixDefinition> {
* Sets the thread pool key to use. The default value is CamelHystrix.
*/
public HystrixDefinition threadPoolKey(String threadPoolKey) {
- setThreadPoolKey(threadPoolKey);
+ configure().threadPoolKey(threadPoolKey);
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f5b47783/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 5317db0..26ea912 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
@@ -53,14 +53,29 @@ 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();
+ HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+ HystrixConfigurationDefinition configRef = null;
+ if (cb.getHystrixConfigurationRef() != null) {
+ configRef = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+ }
+
+ // group and thread pool keys to use they can be configured on configRef and config, so look there first, and if none then use default
+ String groupKey = null;
+ String threadPoolKey = null;
+ if (configRef != null) {
+ groupKey = configRef.getGroupKey();
+ threadPoolKey = configRef.getThreadPoolKey();
+ }
+ if (config != null && config.getGroupKey() != null) {
+ groupKey = config.getGroupKey();
+ threadPoolKey = config.getThreadPoolKey();
}
- if (cb.getThreadPoolKey() != null) {
- threadPoolKey = cb.getThreadPoolKey();
+ if (groupKey == null) {
+ groupKey = HystrixConfigurationDefinition.DEFAULT_GROUP_KEY;
+ }
+ if (threadPoolKey == null) {
+ // thread pool key should use same as group key as default
+ threadPoolKey = groupKey;
}
// create setter using the default options
@@ -73,13 +88,11 @@ public class HystrixProcessorFactory implements ProcessorFactory {
setter.andThreadPoolPropertiesDefaults(threadPool);
// at first configure any shared options
- if (cb.getHystrixConfigurationRef() != null) {
- HystrixConfigurationDefinition config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
- configureHystrix(command, threadPool, config);
+ if (configRef != null) {
+ configureHystrix(command, threadPool, configRef);
}
// then any local configured can override
- if (cb.getHystrixConfiguration() != null) {
- HystrixConfigurationDefinition config = cb.getHystrixConfiguration();
+ if (config != null) {
configureHystrix(command, threadPool, config);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f5b47783/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
index 5faefb9..ebfa660 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteConfigTest.java
@@ -37,7 +37,7 @@ public class HystrixRouteConfigTest extends CamelTestSupport {
@Override
public void configure() throws Exception {
from("direct:start")
- .hystrix().configure().requestCacheEnabled(false).corePoolSize(5).end()
+ .hystrix().configure().groupKey("myCamelApp").requestCacheEnabled(false).corePoolSize(5).end()
.to("direct:foo")
.fallback()
.transform().constant("Fallback message")
http://git-wip-us.apache.org/repos/asf/camel/blob/f5b47783/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
index e7e964a..40a8ccb 100644
--- a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteConfigTest.xml
@@ -25,7 +25,7 @@
<route>
<from uri="direct:start"/>
<hystrix>
- <hystrixConfiguration requestCacheEnabled="false" corePoolSize="5"/>
+ <hystrixConfiguration groupKey="myCamelApp" requestCacheEnabled="false" corePoolSize="5"/>
<to uri="direct:foo"/>
<fallback>
<transform>
[20/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/d14dfbd4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d14dfbd4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d14dfbd4
Branch: refs/heads/master
Commit: d14dfbd455f159567819e7ec5c655072654a8412
Parents: f3bef40
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 18:16:45 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/d14dfbd4/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/d14dfbd4/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/d14dfbd4/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());
}
[14/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is
using hystrix
Posted by da...@apache.org.
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/ca54a546
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ca54a546
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ca54a546
Branch: refs/heads/master
Commit: ca54a546ddde7221c0ebed7aaddfeb8eda793c5f
Parents: 37d3315
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 19 11:42:47 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200
----------------------------------------------------------------------
.../component/hystrix/HystrixProcessor.java | 112 -------------------
.../hystrix/HystrixProcessorCommand.java | 112 -------------------
.../hystrix/HystrixProcessorFactory.java | 54 ---------
.../hystrix/processor/HystrixProcessor.java | 112 +++++++++++++++++++
.../processor/HystrixProcessorCommand.java | 112 +++++++++++++++++++
.../processor/HystrixProcessorFactory.java | 54 +++++++++
.../org/apache/camel/model/HystrixDefinition | 2 +-
.../hystrix/HystrixRouteFallbackTest.java | 53 ---------
.../component/hystrix/HystrixRouteOkTest.java | 53 ---------
.../hystrix/SpringHystrixRouteFallbackTest.java | 40 -------
.../hystrix/SpringHystrixRouteOkTest.java | 40 -------
.../processor/HystrixRouteFallbackTest.java | 53 +++++++++
.../hystrix/processor/HystrixRouteOkTest.java | 53 +++++++++
.../SpringHystrixRouteFallbackTest.java | 40 +++++++
.../processor/SpringHystrixRouteOkTest.java | 40 +++++++
.../hystrix/SpringHystrixRouteFallbackTest.xml | 44 --------
.../hystrix/SpringHystrixRouteOkTest.xml | 46 --------
.../SpringHystrixRouteFallbackTest.xml | 44 ++++++++
.../processor/SpringHystrixRouteOkTest.xml | 46 ++++++++
19 files changed, 555 insertions(+), 555 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
deleted file mode 100644
index 22d48af..0000000
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ /dev/null
@@ -1,112 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.apache.camel.Navigate;
-import org.apache.camel.Processor;
-import org.apache.camel.spi.IdAware;
-import org.apache.camel.support.ServiceSupport;
-import org.apache.camel.util.AsyncProcessorConverterHelper;
-import org.apache.camel.util.AsyncProcessorHelper;
-
-/**
- * Implementation of the Hystrix EIP.
- */
-public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
-
- private String id;
- private final AsyncProcessor processor;
- private final AsyncProcessor fallback;
-
- public HystrixProcessor(String id, Processor processor, Processor fallback) {
- this.id = id;
- this.processor = AsyncProcessorConverterHelper.convert(processor);
- this.fallback = AsyncProcessorConverterHelper.convert(fallback);
- }
-
- @Override
- public String getId() {
- return id;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public String getTraceLabel() {
- return "hystrix";
- }
-
- @Override
- public List<Processor> next() {
- if (!hasNext()) {
- return null;
- }
- List<Processor> answer = new ArrayList<Processor>();
- answer.add(processor);
- if (fallback != null) {
- answer.add(fallback);
- }
- return answer;
- }
-
- @Override
- public boolean hasNext() {
- return true;
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- AsyncProcessorHelper.process(this, exchange);
- }
-
- @Override
- public boolean process(Exchange exchange, AsyncCallback callback) {
- HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
- HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
- try {
- command.queue();
- } catch (Throwable e) {
- // error adding to queue, so set as error and we are done
- exchange.setException(e);
- callback.done(true);
- return true;
- }
-
- return false;
- }
-
- @Override
- protected void doStart() throws Exception {
- // noop
- }
-
- @Override
- protected void doStop() throws Exception {
- // noop
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
deleted file mode 100644
index 1eec854..0000000
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ /dev/null
@@ -1,112 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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;
-
-import com.netflix.hystrix.HystrixCommand;
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Hystrix Command for the Camel Hystrix EIP.
- */
-public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
-
- private static final Logger LOG = LoggerFactory.getLogger(HystrixProcessorCommand.class);
- private final Exchange exchange;
- private final AsyncCallback callback;
- private final AsyncProcessor processor;
- private final AsyncProcessor fallback;
-
- public HystrixProcessorCommand(HystrixCommandGroupKey group, Exchange exchange, AsyncCallback callback,
- AsyncProcessor processor, AsyncProcessor fallback) {
- super(group);
- this.exchange = exchange;
- this.callback = callback;
- this.processor = processor;
- this.fallback = fallback;
- }
-
- @Override
- protected Exchange getFallback() {
- // only run fallback if there was an exception
- Exception exception = exchange.getException();
- if (exception == null) {
- return exchange;
- }
-
- try {
- if (fallback != null) {
- LOG.debug("Error occurred processing. Will now run fallback. Exception class: {} message: {}.", exception.getClass().getName(), exception.getMessage());
- // store the last to endpoint as the failure endpoint
- if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
- exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
- }
- // give the rest of the pipeline another chance
- exchange.setProperty(Exchange.EXCEPTION_HANDLED, true);
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
- exchange.setException(null);
- // and we should not be regarded as exhausted as we are in a try .. catch block
- exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
- // run the fallback processor
- try {
- LOG.debug("Running fallback: {} with exchange: {}", fallback, exchange);
- fallback.process(exchange, callback);
- } catch (Exception e) {
- exchange.setException(e);
- }
- }
- } finally {
- LOG.debug("Running fallback: {} with exchange: {} done", fallback, exchange);
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
- callback.done(false);
- }
-
- return exchange;
- }
-
- @Override
- protected Exchange run() throws Exception {
- LOG.debug("Running processor: {} with exchange: {}", processor, exchange);
-
- // run this as if we run inside try .. catch so there is no regular Camel error handler
- exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
- try {
- processor.process(exchange, callback);
- } catch (Exception e) {
- exchange.setException(e);
- }
-
- // if we failed then throw an exception
- if (exchange.getException() != null) {
- throw exchange.getException();
- }
- // no errors we are done
- try {
- LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
- exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
- callback.done(false);
- } catch (Throwable e) {
- exchange.setException(e);
- }
-
- return exchange;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
deleted file mode 100644
index 5d4cf99..0000000
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorFactory.java
+++ /dev/null
@@ -1,54 +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;
-
-import org.apache.camel.Processor;
-import org.apache.camel.model.HystrixDefinition;
-import org.apache.camel.model.ProcessorDefinition;
-import org.apache.camel.spi.ProcessorFactory;
-import org.apache.camel.spi.RouteContext;
-
-/**
- * To integrate camel-hystrix with the Camel routes using the Hystrix EIP.
- */
-public class HystrixProcessorFactory implements ProcessorFactory {
-
- @Override
- public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
- // not in use
- return null;
- }
-
- @Override
- 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 processor
- Processor processor = cb.createChildProcessor(routeContext, true);
- Processor fallback = null;
- if (cb.getFallback() != null) {
- fallback = cb.getFallback().createProcessor(routeContext);
- }
-
- return new HystrixProcessor(id, processor, fallback);
- } else {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/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
new file mode 100644
index 0000000..c3b272d
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
@@ -0,0 +1,112 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.AsyncProcessorConverterHelper;
+import org.apache.camel.util.AsyncProcessorHelper;
+
+/**
+ * Implementation of the Hystrix EIP.
+ */
+public class HystrixProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, org.apache.camel.Traceable, IdAware {
+
+ private String id;
+ private final AsyncProcessor processor;
+ private final AsyncProcessor fallback;
+
+ public HystrixProcessor(String id, Processor processor, Processor fallback) {
+ this.id = id;
+ this.processor = AsyncProcessorConverterHelper.convert(processor);
+ this.fallback = AsyncProcessorConverterHelper.convert(fallback);
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getTraceLabel() {
+ return "hystrix";
+ }
+
+ @Override
+ public List<Processor> next() {
+ if (!hasNext()) {
+ return null;
+ }
+ List<Processor> answer = new ArrayList<Processor>();
+ answer.add(processor);
+ if (fallback != null) {
+ answer.add(fallback);
+ }
+ return answer;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
+ HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback, processor, fallback);
+ try {
+ command.queue();
+ } catch (Throwable e) {
+ // error adding to queue, so set as error and we are done
+ exchange.setException(e);
+ callback.done(true);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // noop
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
new file mode 100644
index 0000000..16c0645
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java
@@ -0,0 +1,112 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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 com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Hystrix Command for the Camel Hystrix EIP.
+ */
+public class HystrixProcessorCommand extends HystrixCommand<Exchange> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HystrixProcessorCommand.class);
+ private final Exchange exchange;
+ private final AsyncCallback callback;
+ private final AsyncProcessor processor;
+ private final AsyncProcessor fallback;
+
+ public HystrixProcessorCommand(HystrixCommandGroupKey group, Exchange exchange, AsyncCallback callback,
+ AsyncProcessor processor, AsyncProcessor fallback) {
+ super(group);
+ this.exchange = exchange;
+ this.callback = callback;
+ this.processor = processor;
+ this.fallback = fallback;
+ }
+
+ @Override
+ protected Exchange getFallback() {
+ // only run fallback if there was an exception
+ Exception exception = exchange.getException();
+ if (exception == null) {
+ return exchange;
+ }
+
+ try {
+ if (fallback != null) {
+ LOG.debug("Error occurred processing. Will now run fallback. Exception class: {} message: {}.", exception.getClass().getName(), exception.getMessage());
+ // store the last to endpoint as the failure endpoint
+ if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
+ exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
+ }
+ // give the rest of the pipeline another chance
+ exchange.setProperty(Exchange.EXCEPTION_HANDLED, true);
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exception);
+ exchange.setException(null);
+ // and we should not be regarded as exhausted as we are in a try .. catch block
+ exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
+ // run the fallback processor
+ try {
+ LOG.debug("Running fallback: {} with exchange: {}", fallback, exchange);
+ fallback.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ }
+ }
+ } finally {
+ LOG.debug("Running fallback: {} with exchange: {} done", fallback, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ callback.done(false);
+ }
+
+ return exchange;
+ }
+
+ @Override
+ protected Exchange run() throws Exception {
+ LOG.debug("Running processor: {} with exchange: {}", processor, exchange);
+
+ // run this as if we run inside try .. catch so there is no regular Camel error handler
+ exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
+ try {
+ processor.process(exchange, callback);
+ } catch (Exception e) {
+ exchange.setException(e);
+ }
+
+ // if we failed then throw an exception
+ if (exchange.getException() != null) {
+ throw exchange.getException();
+ }
+ // no errors we are done
+ try {
+ LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
+ exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
+ callback.done(false);
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
+
+ return exchange;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/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
new file mode 100644
index 0000000..b6d3a80
--- /dev/null
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.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.component.hystrix.processor;
+
+import org.apache.camel.Processor;
+import org.apache.camel.model.HystrixDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * To integrate camel-hystrix with the Camel routes using the Hystrix EIP.
+ */
+public class HystrixProcessorFactory implements ProcessorFactory {
+
+ @Override
+ public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
+ // not in use
+ return null;
+ }
+
+ @Override
+ 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 processor
+ Processor processor = cb.createChildProcessor(routeContext, true);
+ Processor fallback = null;
+ if (cb.getFallback() != null) {
+ fallback = cb.getFallback().createProcessor(routeContext);
+ }
+
+ return new HystrixProcessor(id, processor, fallback);
+ } else {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
index 0e00349..868615a 100644
--- a/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
+++ b/components/camel-hystrix/src/main/resources/META-INF/services/org/apache/camel/model/HystrixDefinition
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.hystrix.HystrixProcessorFactory
+class=org.apache.camel.component.hystrix.processor.HystrixProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.java
deleted file mode 100644
index dc7c766..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteFallbackTest.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.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixRouteFallbackTest extends CamelTestSupport {
-
- @Test
- public void testHystrix() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrix()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo").errorHandler(noErrorHandler())
- .throwException(new IllegalArgumentException("Forced"));
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.java
deleted file mode 100644
index d5a2d5c..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/HystrixRouteOkTest.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.hystrix;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class HystrixRouteOkTest extends CamelTestSupport {
-
- @Test
- public void testHystrix() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .hystrix()
- .to("direct:foo")
- .fallback()
- .transform().constant("Fallback message")
- .end()
- .to("mock:result");
-
- from("direct:foo")
- .transform().constant("Bye World");
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java
deleted file mode 100644
index 263ab47..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.java
+++ /dev/null
@@ -1,40 +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;
-
-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 SpringHystrixRouteFallbackTest extends CamelSpringTestSupport {
-
- @Override
- protected AbstractApplicationContext createApplicationContext() {
- return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml");
- }
-
- @Test
- public void testHystrix() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java
deleted file mode 100644
index f459a7f..0000000
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.java
+++ /dev/null
@@ -1,40 +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;
-
-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 SpringHystrixRouteOkTest extends CamelSpringTestSupport {
-
- @Override
- protected AbstractApplicationContext createApplicationContext() {
- return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml");
- }
-
- @Test
- public void testHystrix() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
new file mode 100644
index 0000000..b6cced0
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 HystrixRouteFallbackTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo").errorHandler(noErrorHandler())
+ .throwException(new IllegalArgumentException("Forced"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
new file mode 100644
index 0000000..5d90610
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 HystrixRouteOkTest extends CamelTestSupport {
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .hystrix()
+ .to("direct:foo")
+ .fallback()
+ .transform().constant("Fallback message")
+ .end()
+ .to("mock:result");
+
+ from("direct:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
new file mode 100644
index 0000000..5f6064b
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.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.hystrix.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 SpringHystrixRouteFallbackTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
new file mode 100644
index 0000000..fcffb27
--- /dev/null
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.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.hystrix.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 SpringHystrixRouteOkTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.xml");
+ }
+
+ @Test
+ public void testHystrix() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
deleted file mode 100644
index 441b8b6..0000000
--- a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteFallbackTest.xml
+++ /dev/null
@@ -1,44 +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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <hystrix>
- <to uri="direct:foo"/>
- <fallback>
- <transform>
- <constant>Fallback message</constant>
- </transform>
- </fallback>
- </hystrix>
- <to uri="mock:result"/>
- </route>
-
- <route>
- <from uri="direct:foo"/>
- <throwException exceptionType="java.lang.IllegalArgumentException" message="Forced"/>
- </route>
- </camelContext>
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
deleted file mode 100644
index 26fdabc..0000000
--- a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/SpringHystrixRouteOkTest.xml
+++ /dev/null
@@ -1,46 +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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <hystrix>
- <to uri="direct:foo"/>
- <fallback>
- <transform>
- <constant>Fallback message</constant>
- </transform>
- </fallback>
- </hystrix>
- <to uri="mock:result"/>
- </route>
-
- <route>
- <from uri="direct:foo"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </route>
- </camelContext>
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.xml
new file mode 100644
index 0000000..441b8b6
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.xml
@@ -0,0 +1,44 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <hystrix>
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <throwException exceptionType="java.lang.IllegalArgumentException" message="Forced"/>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/ca54a546/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.xml b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.xml
new file mode 100644
index 0000000..26fdabc
--- /dev/null
+++ b/components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.xml
@@ -0,0 +1,46 @@
+<?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://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <hystrix>
+ <to uri="direct:foo"/>
+ <fallback>
+ <transform>
+ <constant>Fallback message</constant>
+ </transform>
+ </fallback>
+ </hystrix>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file