This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 0972954 CAMEL-16861: Cleanup and update EIP docs 0972954 is described below commit 09729544ebf66e48b64868f1e75c5d7b0325568d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Oct 12 14:19:34 2021 +0200 CAMEL-16861: Cleanup and update EIP docs --- .../main/docs/modules/eips/pages/hystrix-eip.adoc | 7 +- .../docs/modules/eips/pages/resilience4j-eip.adoc | 105 +++++++++++---------- .../eips/pages/resilience4jConfiguration-eip.adoc | 5 + 3 files changed, 63 insertions(+), 54 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/hystrix-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/hystrix-eip.adoc index 9362092..8fc4506 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/hystrix-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/hystrix-eip.adoc @@ -3,8 +3,7 @@ The Hystrix EIP provides integration with Netflix https://github.com/Netflix/Hystrix[Hystrix] to be used as xref:circuitBreaker-eip.adoc[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. +Resilience4j is a lightweight fault tolerance library inspired by Netflix Hystrix, but designed for functional programming. == Configuration options @@ -99,9 +98,9 @@ And in XML: ---- In this example if calling the downstream service does not return a response within 2 seconds, -a timeout is triggered, and the exchange will fail with a TimeoutException. +a timeout is triggered, and the exchange will fail with a `TimeoutException`. -== Camel's Error Handler and Circuit Breaker EIP +=== Camel's Error Handler and Circuit Breaker EIP By default, the xref:circuitBreaker-eip.adoc[Circuit Breaker] EIP handles errors by itself. This means if the circuit breaker is open, and the message fails, then Camel's error handler diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4j-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4j-eip.adoc index 9dddc74..5d9100a 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4j-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4j-eip.adoc @@ -1,23 +1,7 @@ = Resilience4j EIP -This component supports the Circuit Breaker EIP with the Resilience4j library. - -[NOTE] -==== -Camel provides the Circuit Breaker EIP in the route model, which allows to plugin different implementations. -Resilience4j is one such implementation. -==== - -Maven users will need to add the following dependency to their pom.xml to use this EIP: - -[source] ----- -<dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-resilience4j</artifactId> - <version>x.x.x</version><!-- use the same version as your Camel core version --> -</dependency> ----- +The Resilience4j EIP provides integration with Resilience4j https://resilience4j.readme.io/[Resilience4j] +to be used as xref:circuitBreaker-eip.adoc[Circuit Breaker] in the Camel routes. == Configuration options @@ -32,11 +16,14 @@ The Resilience4j EIP supports 2 options which are listed below: |=== // eip options: END -See xref:resilience4jConfiguration-eip.adoc[Resilience4j Configuration] for all the configuration options on Resilience Circuit Breaker. +See xref:resilience4jConfiguration-eip.adoc[Resilience4j Configuration] for all the configuration options +on Resilience xref:circuitBreaker-eip.adoc[Circuit Breaker]. + +== Using Resilienc4j EIP -== Samples +Below is an example route showing a Resilience4j circuit breaker +that protects against a downstream HTTP operation with fallback. -Below is an example route showing a Resilience endpoint that protects against a downstream HTTP operation by falling back to the in-lined fallback route. [source,java] ---- from("direct:start") @@ -49,29 +36,35 @@ from("direct:start") ---- And in XML DSL: + [source,xml] ---- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> +<route> <from uri="direct:start"/> <circuitBreaker> - <to uri="http://fooservice.com/faulty"/> - <onFallback> - <transform> - <constant>Fallback message</constant> - </transform> - </onFallback> + <to uri="http://fooservice.com/faulty"/> + <onFallback> + <transform> + <constant>Fallback message</constant> + </transform> + </onFallback> </circuitBreaker> <to uri="mock:result"/> - </route> -</camelContext> +</route> ---- -== Configuring Resilience4j +In case the calling the downstream HTTP service is failing, and an exception is thrown +then the circuit breaker will react and execute the fallback route instead. + +If there was no fallback, then the circuit breaker will throw an exception. + +TIP: For more information about fallback see xref:onFallback-eip.adoc[onFallback]. + +=== Configuring Resilience4j You can fine-tune Resilience4j by the many xref:resilience4jConfiguration-eip.adoc[Resilience4j Configuration] options. -For example to use a 2 second execution timeout, you can do as follows: +For example to use 2 second execution timeout, you can do as follows: [source,java] ---- @@ -80,7 +73,7 @@ from("direct:start") // use 2 second timeout .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(2000).end() .log("Resilience processing start: ${threadName}") - .toD("direct:${body}") + .to("http://fooservice.com/faulty") .log("Resilience processing end: ${threadName}") .end() .log("After Resilience ${body}"); @@ -95,30 +88,24 @@ And in XML: <circuitBreaker> <resilience4jConfiguration timeoutEnabled="true" timeoutDuration="2000"/> <log message="Resilience processing start: ${threadName}"/> - <toD uri="direct:${body}"/> + <to uri="http://fooservice.com/faulty"/> <log message="Resilience processing end: ${threadName}"/> </circuitBreaker> <log message="After Resilience: ${body}"/> </route> ---- -== Fallback - -See xref:onFallback-eip.adoc[onFallback]. - -== Other examples +In this example if calling the downstream service does not return a response within 2 seconds, +a timeout is triggered, and the exchange will fail with a `TimeoutException`. -You can find an example with the source code: https://github.com/apache/camel-spring-boot-examples/tree/master/camel-example-spring-boot-resilience4j[camel-example-spring-boot-resilience4j]. +=== Camel's Error Handler and Circuit Breaker EIP -== Using Resilience4j with Spring Boot +By default, the xref:circuitBreaker-eip.adoc[Circuit Breaker] 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. -See the xref:components:others:resilience4j.adoc[Resilience4j Component]. - -== Camel's Error Handler and Circuit Breaker EIP - -By default the Circuit Breaker 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 circuit breaker by enabling the `inheritErrorHandler` option, as shown: +However, you can enable Camels error handler with circuit breaker by enabling +the `inheritErrorHandler` option, as shown: [source,java] ---- @@ -136,7 +123,7 @@ from("direct:start") .to("mock:result"); ---- -This example is from an unit test, where you can see the Circuit Breaker EIP block has been hardcoded +This example is from a test, where you can see the Circuit Breaker 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 Circuit Breaker EIP block again. @@ -146,3 +133,21 @@ That means the `mock:a` endpoint will receive the message again, and a total of If we turn off the `inheritErrorHandler` option (default) then the Circuit Breaker EIP will only be executed once because it handled the error itself. +== Dependencies + +[NOTE] +==== +Camel provides the xref:circuitBreaker-eip.adoc[Circuit Breaker] EIP in the route model, which allows to plugin different implementations. +Resilience4j is one such implementation. +==== + +Maven users will need to add the following dependency to their pom.xml to use this EIP: + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-resilience4j</artifactId> + <version>x.x.x</version><!-- use the same version as your Camel core version --> +</dependency> +---- diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4jConfiguration-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4jConfiguration-eip.adoc index 16946a8..88df8e0 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4jConfiguration-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/resilience4jConfiguration-eip.adoc @@ -5,7 +5,12 @@ :since: :supportlevel: Stable +This page documents all the specific options for the xref:resilience4j-eip.adoc[Resilience4j] EIP. // eip options: START include::partial$eip-options.adoc[] // eip options: END + +== Example + +See xref:resilience4j-eip.adoc[Resilience4j] EIP for details how to use this EIP.