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/12/29 16:55:32 UTC

[3/4] camel git commit: CAMEL-10662: camel-hystrix - If hystrix timeout occurs then the hystrix timeout exception should be cause

CAMEL-10662: camel-hystrix - If hystrix timeout occurs then the hystrix timeout exception should be cause


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

Branch: refs/heads/master
Commit: 5807f21123093abf98472321340f59cfca293b54
Parents: 28dcd43
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Dec 29 14:16:59 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Dec 29 17:54:07 2016 +0100

----------------------------------------------------------------------
 .../hystrix/processor/HystrixProcessorCommand.java  | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5807f211/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 4face6e..4d86ef7 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,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import com.netflix.hystrix.HystrixCommand;
+import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
@@ -45,10 +46,10 @@ public class HystrixProcessorCommand extends HystrixCommand {
 
     @Override
     protected Message getFallback() {
-        // grab the exception that caused the error (can be failure in run, or from hystrix if short circuited)
-        Throwable exception = getExecutionException();
-
         if (fallback != null || fallbackCommand != null) {
+            // grab the exception that caused the error (can be failure in run, or from hystrix if short circuited)
+            Throwable exception = getExecutionException();
+
             if (exception != null) {
                 LOG.debug("Error occurred processing. Will now run fallback. Exception class: {} message: {}.", exception.getClass().getName(), exception.getMessage());
             } else {
@@ -100,13 +101,20 @@ public class HystrixProcessorCommand extends HystrixCommand {
         // is fallback enabled
         Boolean fallbackEnabled = getProperties().fallbackEnabled().get();
 
+        // execution exception must take precedence over exchange exception
+        // because hystrix may have caused this command to fail due timeout or something else
+        Throwable exception = getExecutionException();
+        if (exception != null) {
+            exchange.setException(new CamelExchangeException("Hystrix execution exception occurred while processing Exchange", exchange, exception));
+        }
+
         // if we failed then throw an exception if fallback is enabled
         if (fallbackEnabled == null || fallbackEnabled && exchange.getException() != null) {
             throw exchange.getException();
         }
 
-        LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
         // no fallback then we are done
+        LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
         return exchange.hasOut() ? exchange.getOut() : exchange.getIn();
     }
 }