This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-14182
in repository https://gitbox.apache.org/repos/asf/camel.git

commit eabddf9b70638aa73e5b730b0477101441b3691d
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Nov 15 10:28:53 2019 +0100

    CAMEL-14182: Make Hystrix EIP general as Circuit Breaker EIP and allow to 
plugin other implementations. WIP
---
 .../ROOT/pages/camel-3-migration-guide.adoc        |   8 ++
 .../modules/ROOT/pages/hystrix-eip.adoc            | 115 ++++++++++++++-------
 .../modules/ROOT/pages/onFallback-eip.adoc         |  17 +--
 .../org/apache/camel/itest/CamelHystrixTest.xml    |   4 +-
 4 files changed, 100 insertions(+), 44 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-3-migration-guide.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-3-migration-guide.adoc
index 257bd91..cb76c12 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3-migration-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3-migration-guide.adoc
@@ -161,6 +161,14 @@ The `rxjava2` component has been renamed to `rxjava`, and 
it's corresponding com
 
 We have also renamed `camel-jetty9` to `camel-jetty`. The supported scheme is 
now `jetty`.
 
+=== Hystrix EIP
+
+The Hystrix EIP has been generalized as circuit breaker to allow to plugin 
other implementations.
+
+In the Java DSL you need to migrate from `.hystrix()` to `.circuitBreaker()`.
+And in XML DSL `<hystrix>` should be `<circuitBreaker>`.
+
+
 === Using endpoint options with consumer. prefix
 
 Endpoints with `consumer.` prefix such as `consumer.delay=5000` are no longer 
supported (deprecated in latest Camel 2.x) and you should just use the option 
without the `consumer.` prefix, eg `delay=5000`.
diff --git a/docs/user-manual/modules/ROOT/pages/hystrix-eip.adoc 
b/docs/user-manual/modules/ROOT/pages/hystrix-eip.adoc
index cb3fe18..2cd1eb5 100644
--- a/docs/user-manual/modules/ROOT/pages/hystrix-eip.adoc
+++ b/docs/user-manual/modules/ROOT/pages/hystrix-eip.adoc
@@ -6,6 +6,9 @@
 
 The Hystrix EIP provides integration with Netflix 
https://github.com/Netflix/Hystrix[Hystrix] to be used as circuit breaker in 
the Camel routes. Hystrix is a latency and fault tolerance library designed to 
isolate points of access to remote systems, services and 3rd party libraries, 
stop cascading failure and enable resilience in complex distributed systems 
where failure is inevitable.
 
+NOTE: Camel provides the Circuit Breaker EIP in the route model, which allows 
to plugin different implementations.
+Hystrix is one such implementation.
+
 Maven users will need to add the following dependency to their pom.xml to use 
this EIP:
 
 [source]
@@ -30,38 +33,7 @@ The Hystrix EIP supports 2 options which are listed below:
 |===
 // eip options: END
 
-== Camel's Error Handler and Hystrix EIP
-
-By default the Hystrix EIP handles errors by itself. This means if the circuit 
breaker is open and
-the message fails, then Camel's error handler is not reacting also.
-However, you can enable Camels error handler with Hystrix by enabling the 
`inheritErrorHandler` option, as shown:
-
-[source,java]
-----
-// Camel's error handler that will attempt to redeliver the message 3 times
-errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(3).redeliveryDelay(0));
-
-from("direct:start")
-    .to("log:start")
-    // turn on Camel's error handler on hystrix so it can do redeliveries
-    .hystrix().inheritErrorHandler(true)
-        .to("mock:a")
-        .throwException(new IllegalArgumentException("Forced"))
-    .end()
-    .to("log:result")
-    .to("mock:result");
-----
-
-This example is from an unit test, where you can see the Hystrix EIP block has 
been hardcoded
-to always fail by throwning an exception. Because the `inheritErrorHandler` 
has been enabled,
-then Camel's error handler will attempt to call the Hystrix EIP block again.
-
-That means the `mock:a` endpoint will receive the message again, and a total 
of 1 + 3 = 4 message
-(first time + 3 redeliveries).
-
-If we turn off the `inheritErrorHandler` option (default) then the Hystrix EIP 
will only be
-executed once because it handled the error itself.
-
+See xref:hystrixConfiguration-eip.adoc[Hystrix Configuration] for all the 
configuration options on Hystrix EIP.
 
 == Samples
 
@@ -69,7 +41,7 @@ Below is an example route showing an Hystrix endpoint that 
protects against slow
 [source,java]
 ----
 from("direct:start")
-    .hystrix()
+    .circuitBreaker()
         .to("http://fooservice.com/slow";)
     .onFallback()
         .transform().constant("Fallback message")
@@ -83,21 +55,94 @@ And in XML DSL:
 <camelContext xmlns="http://camel.apache.org/schema/spring";>
   <route>
     <from uri="direct:start"/>
-    <hystrix>
+    <circuitBreaker>
       <to uri="http://fooservice.com/slow"/>
       <onFallback>
         <transform>
           <constant>Fallback message</constant>
         </transform>
       </onFallback>
-    </hystrix>
+    </circuitBreaker>
     <to uri="mock:result"/>
   </route>
 </camelContext>
 ----
 
+== Configuring Hystrix
+
+You can fine-tune Hystrix by the many 
xref:hystrixConfiguration-eip.adoc[Hystrix Configuration] options.
+For example to use a 2 second execution timeout, you can do as follows:
+
+[source,java]
+----
+from("direct:start")
+    .circuitBreaker()
+        // use 2 second timeout
+        .hystrixConfiguration().executionTimeoutInMilliseconds(2000).end()
+        .log("Hystrix processing start: ${threadName}")
+        .toD("direct:${body}")
+        .log("Hystrix processing end: ${threadName}")
+    .end()
+    .log("After Hystrix ${body}");
+----
+
+And in XML:
+
+[source,xml]
+----
+<route>
+  <from uri="direct:start"/>
+  <circuitBreaker>
+    <hystrixConfiguration executionTimeoutInMilliseconds="2000"/>
+    <log message="Hystrix processing start: ${threadName}"/>
+    <toD uri="direct:${body}"/>
+    <log message="Hystrix processing end: ${threadName}"/>
+  </circuitBreaker>
+  <log message="After Hystrix: ${body}"/>
+</route>
+----
+
+== Fallback
+
 See xref:onFallback-eip.adoc[onFallback].
 
 == Other examples
 
 You can find an example with the source code: 
https://github.com/apache/camel/tree/master/examples/camel-example-hystrix[camel-example-hystrix].
+
+== Using Hystrix with Spring Boot
+
+See the xref:hystrix-component.adoc[Hystrix Component].
+
+== Camel's Error Handler and Hystrix EIP
+
+By default the Hystrix EIP handles errors by itself. This means if the circuit 
breaker is open and
+the message fails, then Camel's error handler is not reacting also.
+However, you can enable Camels error handler with Hystrix by enabling the 
`inheritErrorHandler` option, as shown:
+
+[source,java]
+----
+// Camel's error handler that will attempt to redeliver the message 3 times
+errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(3).redeliveryDelay(0));
+
+from("direct:start")
+    .to("log:start")
+    // turn on Camel's error handler on hystrix so it can do redeliveries
+    .circuitBreaker().inheritErrorHandler(true)
+        .to("mock:a")
+        .throwException(new IllegalArgumentException("Forced"))
+    .end()
+    .to("log:result")
+    .to("mock:result");
+----
+
+This example is from an unit test, where you can see the Hystrix EIP block has 
been hardcoded
+to always fail by throwing an exception. Because the `inheritErrorHandler` has 
been enabled,
+then Camel's error handler will attempt to call the Hystrix EIP block again.
+
+That means the `mock:a` endpoint will receive the message again, and a total 
of 1 + 3 = 4 message
+(first time + 3 redeliveries).
+
+If we turn off the `inheritErrorHandler` option (default) then the Hystrix EIP 
will only be
+executed once because it handled the error itself.
+
diff --git a/docs/user-manual/modules/ROOT/pages/onFallback-eip.adoc 
b/docs/user-manual/modules/ROOT/pages/onFallback-eip.adoc
index 94b7d21..54264ad 100644
--- a/docs/user-manual/modules/ROOT/pages/onFallback-eip.adoc
+++ b/docs/user-manual/modules/ROOT/pages/onFallback-eip.adoc
@@ -2,9 +2,9 @@
 = On Fallback EIP
 :page-source: core/camel-core-engine/src/main/docs/eips/onFallback-eip.adoc
 
-If you are using *onFallback* then that is intended to be local processing 
only where you can do a message transformation or call a bean or something as 
the fallback. If you need to call an external service over the network then you 
should use *onFallbackViaNetwork* that runs in another independent 
*HystrixCommand* that uses its own thread pool to not exhaust the first command.
-Configuring Hystrix Example
-Hystrix has many options as listed in the table above. For example to set a 
higher timeout to *5* seconds, and also let the circuit breaker wait *10* 
seconds before attempting a request again when the state was tripped to be open.
+If you are using *onFallback* then that is intended to be local processing 
only where you can do a message transformation or call a bean or something as 
the fallback.
+
+If you need to call an external service over the network then you should use 
*onFallbackViaNetwork* that runs in another independent *HystrixCommand* that 
uses its own thread pool to not exhaust the first command.
 
 == Options
 
@@ -18,10 +18,13 @@ The On Fallback EIP supports 1 options which are listed 
below:
 |===
 // eip options: END
 
+Hystrix has many options as listed in 
xref:hystrixConfiguration-eip.adoc[Hystrix Configuration].
+For example to set a higher timeout to *5* seconds, and also let the circuit 
breaker wait *10* seconds before attempting a request again when the state was 
tripped to be open.
+
 [source,java]
 ----
 from("direct:start")
-    .hystrix()
+    .circuitBreaker()
         .hystrixConfiguration()
              .executionTimeoutInMilliseconds(5000)
              .circuitBreakerSleepWindowInMilliseconds(10000)
@@ -39,7 +42,7 @@ And in XML DSL:
 <camelContext xmlns="http://camel.apache.org/schema/spring";>
   <route>
     <from uri="direct:start"/>
-    <hystrix>
+    <circuitBreaker>
       <hystrixConfiguration executionTimeoutInMilliseconds="5000"
                             circuitBreakerSleepWindowInMilliseconds="10000"/>
       <to uri="http://fooservice.com/slow"/>
@@ -48,7 +51,7 @@ And in XML DSL:
           <constant>Fallback message</constant>
         </transform>
       </onFallback>
-    </hystrix>
+    </circuitBreaker>
     <to uri="mock:result"/>
   </route>
 </camelContext>
@@ -67,7 +70,7 @@ You can also configure Hystrix globally and then refer to 
that configuration:
 
   <route>
     <from uri="direct:start"/>
-    <hystrix hystrixConfigurationRef="sharedConfig">
+    <circuitBreaker configurationRef="sharedConfig">
       <to uri="http://fooservice.com/slow"/>
       <onFallback>
         <transform>
diff --git 
a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelHystrixTest.xml
 
b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelHystrixTest.xml
index 8f12bac..e31b472 100644
--- 
a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelHystrixTest.xml
+++ 
b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelHystrixTest.xml
@@ -26,14 +26,14 @@
 
     <route>
       <from uri="direct:start"/>
-      <hystrix>
+      <circuitBreaker>
         <throwException exceptionType="java.lang.IllegalArgumentException" 
message="Forced"/>
         <onFallback>
           <transform>
             <constant>Fallback message</constant>
           </transform>
         </onFallback>
-      </hystrix>
+      </circuitBreaker>
       <to uri="mock:result"/>
     </route>
 

Reply via email to