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 73f21f5 CAMEL-16861: Cleanup and update EIP docs 73f21f5 is described below commit 73f21f5a161222863d14fdd5fc1a54a390e1194a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Oct 8 10:38:40 2021 +0200 CAMEL-16861: Cleanup and update EIP docs --- .../apache/camel/catalog/models/onFallback.json | 2 +- .../main/docs/modules/eips/pages/normalizer.adoc | 22 ++++--- .../docs/modules/eips/pages/onFallback-eip.adoc | 69 +++------------------- .../docs/modules/eips/pages/otherwise-eip.adoc | 65 -------------------- .../src/main/docs/modules/eips/pages/when-eip.adoc | 65 -------------------- .../org/apache/camel/model/onFallback.json | 2 +- .../apache/camel/model/OnFallbackDefinition.java | 2 +- 7 files changed, 25 insertions(+), 202 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/onFallback.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/onFallback.json index 2e5ae9d..bfa0fcf 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/onFallback.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/onFallback.json @@ -3,7 +3,7 @@ "kind": "model", "name": "onFallback", "title": "On Fallback", - "description": "Route to be executed when Hystrix EIP executes fallback", + "description": "Route to be executed when Circuit Breaker EIP executes fallback", "deprecated": false, "label": "eip,routing", "javaType": "org.apache.camel.model.OnFallbackDefinition", diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc index cba547a..7a9c6e4 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc @@ -13,10 +13,10 @@ In Apache Camel, you can implement the normalizer pattern by combining a xref:ch which detects the incoming message's format, with a collection of different xref:message-translator.adoc[Message Translator]'s, which transform the different incoming formats into a common format. -== Sample +== Example This example shows a Message Normalizer that converts two types of XML messages into a common format. -Messages in this common format are then filtered. +Messages in this common format are then routed. [source,java] ---- @@ -29,18 +29,21 @@ from("direct:start") .to("mock:result"); ---- -In this case we're using a Java bean as the normalizer. The class looks like this +In this case we're using a Java xref:components::bean-component.adoc[Bean] as the normalizer. + +The class looks like this: [source,java] ---- // Java public class MyNormalizer { + public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) { - exchange.getOut().setBody(createPerson(name)); + exchange.getMessage().setBody(createPerson(name)); } public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) { - exchange.getOut().setBody(createPerson(name)); + exchange.getMessage().setBody(createPerson(name)); } private String createPerson(String name) { @@ -49,7 +52,7 @@ public class MyNormalizer { } ---- -The same example in the XML DSL +The same example in XML: [source,xml] ---- @@ -71,4 +74,9 @@ The same example in the XML DSL </camelContext> <bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/> ----- \ No newline at end of file +---- + +In case there are many incoming formats, then the xref:choice-eip.adoc[Content Based Router] +may end up with too many choices. In this situation then an alternative is to use xref:toD-eip.adoc[Dynamic to] +that computes a xref:components::bean-component.adoc[Bean] endpoint, to be called that acts as +xref:message-translator.adoc[Message Translator]. diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/onFallback-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/onFallback-eip.adoc index dfe752f..8a38163 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/onFallback-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/onFallback-eip.adoc @@ -1,7 +1,7 @@ = On Fallback EIP :doctitle: On Fallback :shortname: onFallback -:description: Route to be executed when Hystrix EIP executes fallback +:description: Route to be executed when Circuit Breaker EIP executes fallback :since: :supportlevel: Stable @@ -15,67 +15,12 @@ If you need to call an external service over the network then you should use *on include::partial$eip-options.adoc[] // 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. +== Using fallback -[source,java] ----- -from("direct:start") - .circuitBreaker() - .hystrixConfiguration() - .executionTimeoutInMilliseconds(5000) - .circuitBreakerSleepWindowInMilliseconds(10000) - .end() // end Hystrix configuration - .to("http://fooservice.com/slow") - .onFallback() - .transform().constant("Fallback message") - .end() - .to("mock:result"); ----- +The *onFallback* is used by xref:circuitBreaker-eip.adoc[Circuit Breaker] EIPs to execute a fallback route. +For examples how to use this see the various Circuit Breaker implementations: -And in XML DSL: -[source,xml] ----- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:start"/> - <circuitBreaker> - <hystrixConfiguration executionTimeoutInMilliseconds="5000" - circuitBreakerSleepWindowInMilliseconds="10000"/> - <to uri="http://fooservice.com/slow"/> - <onFallback> - <transform> - <constant>Fallback message</constant> - </transform> - </onFallback> - </circuitBreaker> - <to uri="mock:result"/> - </route> -</camelContext> ----- +- xref:fault-tolerance-eip.adoc[FaultTolerance EIP] - MicroProfile Fault Tolerance Circuit Breaker +- xref:resilience4j-eip.adoc[Resilience4j EIP] - Resilience4j Circuit Breaker +- xref:hystrix-eip.adoc[Hystrix EIP] - Netflix Hystrix Circuit Breaker *deprecated* -You can also configure Hystrix globally and then refer to that configuration: - -[source,xml] ----- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - - <!-- a shared config which you can refer to from all your Hystrix EIPs --> - <hystrixConfiguration id="sharedConfig" - executionTimeoutInMilliseconds="5000" - circuitBreakerSleepWindowInMilliseconds="10000"/> - - <route> - <from uri="direct:start"/> - <circuitBreaker configurationRef="sharedConfig"> - <to uri="http://fooservice.com/slow"/> - <onFallback> - <transform> - <constant>Fallback message</constant> - </transform> - </onFallback> - </hystrix> - <to uri="mock:result"/> - </route> -</camelContext> ----- diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/otherwise-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/otherwise-eip.adoc deleted file mode 100644 index bcd7ec1..0000000 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/otherwise-eip.adoc +++ /dev/null @@ -1,65 +0,0 @@ -= Otherwise EIP -:doctitle: Otherwise -:shortname: otherwise -:description: Route to be executed when all other choices evaluate to false -:since: -:supportlevel: Stable - -The Otherwise EIP is related to http://www.enterpriseintegrationpatterns.com/ContentBasedRouter.html[Content -Based Router] from the xref:enterprise-integration-patterns.adoc[EIP -patterns] - -image::eip/ContentBasedRouter.gif[image] - -== Options - -// eip options: START -include::partial$eip-options.adoc[] -// eip options: END - -== Examples - -The following example shows how to route a request from an input -*direct:a* endpoint to either *direct:b*, *direct:c* or *direct:d* depending on -the evaluation of various xref:latest@manual:ROOT:predicate.adoc[Predicate] expressions - -[source,java] ----- -RouteBuilder builder = new RouteBuilder() { - public void configure() { - from("direct:a") - .choice() - .when(simple("${header.foo} == 'bar'")) - .to("direct:b") - .when(simple("${header.foo} == 'cheese'")) - .to("direct:c") - .otherwise() - .to("direct:d"); - } -}; ----- - - -And the same example using XML: - -[source,xml] ----- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:a"/> - <choice> - <when> - <simple>${header.foo} == 'bar'</simple> - <to uri="direct:b"/> - </when> - <when> - <simple>${header.foo} == 'cheese'</simple> - <to uri="direct:c"/> - </when> - <otherwise> - <to uri="direct:d"/> - </otherwise> - </choice> - </route> -</camelContext> ----- diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/when-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/when-eip.adoc deleted file mode 100644 index e1062e1..0000000 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/when-eip.adoc +++ /dev/null @@ -1,65 +0,0 @@ -= When EIP -:doctitle: When -:shortname: when -:description: Triggers a route when the expression evaluates to true -:since: -:supportlevel: Stable - -The When EIP is related to http://www.enterpriseintegrationpatterns.com/ContentBasedRouter.html[Content -Based Router] from the xref:enterprise-integration-patterns.adoc[EIP -patterns] - -image::eip/ContentBasedRouter.gif[image] - -== Options - -// eip options: START -include::partial$eip-options.adoc[] -// eip options: END - -== Examples - -The following example shows how to route a request from an input -*direct:a* endpoint to either *direct:b*, *direct:c* or *direct:d* depending on -the evaluation of various xref:latest@manual:ROOT:predicate.adoc[Predicate] expressions - -[source,java] ----- -RouteBuilder builder = new RouteBuilder() { - public void configure() { - from("direct:a") - .choice() - .when(simple("${header.foo} == 'bar'")) - .to("direct:b") - .when(simple("${header.foo} == 'cheese'")) - .to("direct:c") - .otherwise() - .to("direct:d"); - } -}; ----- - - -And the same example using XML: - -[source,xml] ----- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:a"/> - <choice> - <when> - <simple>${header.foo} == 'bar'</simple> - <to uri="direct:b"/> - </when> - <when> - <simple>${header.foo} == 'cheese'</simple> - <to uri="direct:c"/> - </when> - <otherwise> - <to uri="direct:d"/> - </otherwise> - </choice> - </route> -</camelContext> ----- diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/onFallback.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/onFallback.json index 2e5ae9d..bfa0fcf 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/onFallback.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/onFallback.json @@ -3,7 +3,7 @@ "kind": "model", "name": "onFallback", "title": "On Fallback", - "description": "Route to be executed when Hystrix EIP executes fallback", + "description": "Route to be executed when Circuit Breaker EIP executes fallback", "deprecated": false, "label": "eip,routing", "javaType": "org.apache.camel.model.OnFallbackDefinition", diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java index 219a470..cfe5c0f 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java @@ -28,7 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement; import org.apache.camel.spi.Metadata; /** - * Route to be executed when Hystrix EIP executes fallback + * Route to be executed when Circuit Breaker EIP executes fallback */ @Metadata(label = "eip,routing") @XmlRootElement(name = "onFallback")