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 2019/11/18 09:00:58 UTC

[camel] 16/23: CAMEL-13691: camel-resilience4j - WIP

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

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

commit d59416ad1d50f9930885e4017cf1570fb8c92e4b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 18 05:54:32 2019 +0100

    CAMEL-13691: camel-resilience4j - WIP
---
 .../src/main/docs/eips/circuitBreaker-eip.adoc     | 53 ----------------------
 .../src/main/docs/eips/hystrix-eip.adoc            |  4 +-
 .../src/main/docs/eips/resilience4j-eip.adoc       | 29 +++++++-----
 3 files changed, 20 insertions(+), 66 deletions(-)

diff --git a/core/camel-core-engine/src/main/docs/eips/circuitBreaker-eip.adoc b/core/camel-core-engine/src/main/docs/eips/circuitBreaker-eip.adoc
deleted file mode 100644
index 95d3056..0000000
--- a/core/camel-core-engine/src/main/docs/eips/circuitBreaker-eip.adoc
+++ /dev/null
@@ -1,53 +0,0 @@
-[[circuitBreaker-eip]]
-= Circuit Breaker EIP (deprecated)
-
-The Circuit Breaker load balancer is a stateful pattern that monitors all calls for certain exceptions. Initially the Circuit Breaker is in closed state and passes all messages. If there are failures and the threshold is reached, it moves to open state and rejects all calls until halfOpenAfter 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.
-When the circuit breaker is closed, it will throw a `java.util.concurrent.RejectedExecutionException`. This can then be caught to provide an alternate path for processing exchanges.
-
-// eip options: START
-The Circuit Breaker EIP supports 3 options which are listed below:
-
-[width="100%",cols="2,5,^1,2",options="header"]
-|===
-| Name | Description | Default | Type
-| *exception* | A list of class names for specific exceptions to monitor. If no exceptions is configured then all exceptions is monitored |  | List
-| *halfOpenAfter* | The timeout in millis to use as threshold to move state from closed to half-open or open state |  | Long
-| *threshold* | Number of previous failed messages to use as threshold to move state from closed to half-open or open state |  | Integer
-|===
-// eip options: END
-
-
-An example using Java DSL:
-[source,java]
-----
-from("direct:start")
-    .onException(RejectedExecutionException.class)
-        .handled(true)
-        .to("mock:serviceUnavailable")
-    .end()
-    .loadBalance()
-        .circuitBreaker(2, 1000L, MyCustomException.class)
-        .to("mock:service")
-    .end();
-----
-
-And the same example using Spring XML:
-[source,xml]
-----
-<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-    <route>
-        <from uri="direct:start"/>
-        <onException>
-            <exception>java.util.concurrent.RejectedExecutionException</exception>
-            <handled><constant>true</constant></handled>
-            <to uri="mock:serviceUnavailable"/>
-        </onException>
-        <loadBalance>
-            <circuitBreaker threshold="2" halfOpenAfter="1000">
-                <exception>MyCustomException</exception>
-            </circuitBreaker>
-            <to uri="mock:service"/>
-        </loadBalance>
-    </route>
-</camelContext>
-----
diff --git a/core/camel-core-engine/src/main/docs/eips/hystrix-eip.adoc b/core/camel-core-engine/src/main/docs/eips/hystrix-eip.adoc
index b2d3a16..5323d15 100644
--- a/core/camel-core-engine/src/main/docs/eips/hystrix-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/eips/hystrix-eip.adoc
@@ -10,7 +10,7 @@ Hystrix is one such implementation.
 
 Maven users will need to add the following dependency to their pom.xml to use this EIP:
 
-[source]
+[source,xml]
 ----
 <dependency>
     <groupId>org.apache.camel</groupId>
@@ -27,7 +27,7 @@ The Hystrix EIP supports 2 options which are listed below:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *hystrixConfiguration* | Configures the Hystrix EIP Use end when configuration is complete, to return back to the Hystrix EIP. |  | HystrixConfiguration Definition
+| *hystrixConfiguration* | Configures the Hystrix EIP Use end when configuration is complete, to return back to the Hystrix EIP. |  | HystrixConfigurationDefinition
 | *hystrixConfigurationRef* | Refers to a Hystrix configuration to use for configuring the Hystrix EIP. |  | String
 |===
 // eip options: END
diff --git a/core/camel-core-engine/src/main/docs/eips/resilience4j-eip.adoc b/core/camel-core-engine/src/main/docs/eips/resilience4j-eip.adoc
index 1137147..9a0ad62 100644
--- a/core/camel-core-engine/src/main/docs/eips/resilience4j-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/eips/resilience4j-eip.adoc
@@ -22,6 +22,14 @@ Maven users will need to add the following dependency to their pom.xml to use th
 == Configuration options
 
 // eip options: START
+The Hystrix EIP supports 2 options which are listed below:
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *resilienceConfiguration* | Configures the Resilience EIP Use end when configuration is complete, to return back to the Resilience EIP. |  | ResilienceConfigurationDefinition
+| *resilienceConfigurationRef* | Refers to a Resilience configuration to use for configuring the Resilience EIP. |  | String
+|===
 // eip options: END
 
 See xref:resilience4jConfiguration-eip.adoc[Resilience4j Configuration] for all the configuration options on Resilience Circuit Breaker.
@@ -59,11 +67,10 @@ And in XML DSL:
 </camelContext>
 ----
 
-== Configuring Resilienc4j
+== Configuring Resilience4j
 
 You can fine-tune Resilience4j by the many xref:resilience4jConfiguration-eip.adoc[Resilience4j Configuration] options.
 
-TODO: Update example!!!
 For example to use a 2 second execution timeout, you can do as follows:
 
 [source,java]
@@ -71,12 +78,12 @@ For example to use a 2 second execution timeout, you can do as follows:
 from("direct:start")
     .circuitBreaker()
         // use 2 second timeout
-        .hystrixConfiguration().executionTimeoutInMilliseconds(2000).end()
-        .log("Hystrix processing start: ${threadName}")
+        .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end()
+        .log("Resilience processing start: ${threadName}")
         .toD("direct:${body}")
-        .log("Hystrix processing end: ${threadName}")
+        .log("Resilience processing end: ${threadName}")
     .end()
-    .log("After Hystrix ${body}");
+    .log("After Resilience ${body}");
 ----
 
 And in XML:
@@ -86,12 +93,12 @@ And in XML:
 <route>
   <from uri="direct:start"/>
   <circuitBreaker>
-    <hystrixConfiguration executionTimeoutInMilliseconds="2000"/>
-    <log message="Hystrix processing start: ${threadName}"/>
+    <resilience4jConfiguration timeoutEnabled="true" timeoutDuration="2000"/>
+    <log message="Resilience processing start: ${threadName}"/>
     <toD uri="direct:${body}"/>
-    <log message="Hystrix processing end: ${threadName}"/>
+    <log message="Resilience processing end: ${threadName}"/>
   </circuitBreaker>
-  <log message="After Hystrix: ${body}"/>
+  <log message="After Resilience: ${body}"/>
 </route>
 ----
 
@@ -101,7 +108,7 @@ 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].
+You can find an example with the source code: https://github.com/apache/camel/tree/master/examples/camel-example-resilience4j[camel-example-resilience4j].
 
 == Using Resilience4j with Spring Boot