This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6e48953d28975aba82b77631bdfdc7fa94b3818e Author: Willem Jiang <jiangni...@huawei.com> AuthorDate: Sun May 13 14:25:56 2018 +0800 Added route-builder and routes to the user-manual, and update the see also links --- docs/user-manual/en/camelcontext.adoc | 6 +- docs/user-manual/en/dsl.adoc | 12 ++-- docs/user-manual/en/route-builder.adoc | 9 +++ docs/user-manual/en/routes.adoc | 112 +++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 9 deletions(-) diff --git a/docs/user-manual/en/camelcontext.adoc b/docs/user-manual/en/camelcontext.adoc index 10da00b..2eadb51 100644 --- a/docs/user-manual/en/camelcontext.adoc +++ b/docs/user-manual/en/camelcontext.adoc @@ -8,15 +8,15 @@ represents a single Camel routing rulebase. You use the CamelContext in a similar way to the Spring http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/ApplicationContext.html[ApplicationContext]. -See Lifecycle to understand the overall lifecycle +See link:lifecycle.adoc[Lifecycle] to understand the overall lifecycle of the CamelContext. [[CamelContext-SeeAlso]] See Also ^^^^^^^^ -* RouteBuilder -* Routes +* link:route-builder.adoc[RouteBuilder] +* link:routes.adoc[Routes] * link:lifecycle.adoc[Lifecycle] * link:architecture.adoc[Architecture] diff --git a/docs/user-manual/en/dsl.adoc b/docs/user-manual/en/dsl.adoc index 3e1c224..b72742e 100644 --- a/docs/user-manual/en/dsl.adoc +++ b/docs/user-manual/en/dsl.adoc @@ -7,18 +7,18 @@ link:enterprise-integration-patterns.html[Enterprise Integration Patterns] or Routes in a variety of domain-specific languages (DSL) as listed below. -* Java DSL - A Java based DSL using the fluent +* link:java-dsl.adoc[Java DSL] - A Java based DSL using the fluent builder style. * Spring XML - A XML based DSL in Spring XML files * Blueprint XML - A XML based DSL in OSGi Blueprint XML files * Rest DSL - A DSL to define REST services using a REST style in either Java or XML. -* Groovy DSL - A Groovy based DSL using Groovy +* link:groovy-dsl.adoc[Groovy DSL] - A Groovy based DSL using Groovy programming language -* Scala DSL - A Scala based DSL using Scala +* link:scala-dsl.adoc[Scala DSL] - A Scala based DSL using Scala programming language -* Annotation DSL - Use annotations in Java +* link:bean-integration.adoc[Annotation DSL] - Use annotations in Java beans. * https://github.com/koolio/kool/tree/master/kool-camel[Kotlin DSL] - *Work in progress* - Currently developed outside ASF, but will we @@ -26,7 +26,7 @@ included later in Camel when Kotlin and the DSL is ready. The main entry points for the DSL are -* CamelContext for creating a Camel routing +* link:camelcontext.adoc[CamelContext] for creating a Camel routing rulebase * RouteBuilder for creating a collection of routes using the routing DSL @@ -39,6 +39,6 @@ For more examples of the DSL in action see * link:enterprise-integration-patterns.adoc[Enterprise Integration Patterns] +* link:routes.adoc[Routes] * Examples -* Routes diff --git a/docs/user-manual/en/route-builder.adoc b/docs/user-manual/en/route-builder.adoc new file mode 100644 index 0000000..a021f9d --- /dev/null +++ b/docs/user-manual/en/route-builder.adoc @@ -0,0 +1,9 @@ +[[RouteBuilder-RouteBuilder]] +RouteBuilder +~~~~~~~~~~~~ +The RouteBuilder is a base class which is derived from to create routing rules using the DSL. Instances of RouteBuilder are then added to the CamelContext. + +See Also +* link:camelcontext.adoc[CamelContext] +* link:routes.adoc[Routes] +* link:architecture.adoc[Architecture] diff --git a/docs/user-manual/en/routes.adoc b/docs/user-manual/en/routes.adoc new file mode 100644 index 0000000..75c238b --- /dev/null +++ b/docs/user-manual/en/routes.adoc @@ -0,0 +1,112 @@ +[[Routes-Routes]] +Routes +~~~~~~ + +Camel supports the definition of routing rules using a Java DSL (domain specific language) which avoids the need for cumbersome XML using a RouteBuilder. + +For example a simple route can be created as follows. +[source,java] +------------------------------------------------------ +RouteBuilder builder = new RouteBuilder() { + public void configure() { + errorHandler(deadLetterChannel("mock:error")); + + from("direct:a").to("direct:b"); + } +}; +------------------------------------------------------ + +As you can see from the above Camel uses URIs to wire endpoints together. + +[[Routes-URI-String-Formatting]] +URI String formatting +^^^^^^^^^^^^^^^^^^^^^^ +Available as of Camel 2.0 + +If you have endpoint URIs that accept options and you want to be able to substitute the value, e.g. build the URI by concat the strings together, then you can use the java.lang.String.format method. But in Camel 2.0 we have added two convenient methods in the Java DSL so you can do fromF and toF that uses String formatting to build the URI. + +[source,java] +-------------------------------------------------------------------- +from("direct:start").toF("file://%s?fileName=%s", path, name); + +fromF("file://%s?include=%s", path, pattern).toF("mock:%s", result); +-------------------------------------------------------------------- + +[[Routes-Filters]] +Filters +^^^^^^^ +You can combine simple routes with filters which can be arbitrary Predicate implementations. + +[source,java] +------------------------------------------------------------- +RouteBuilder builder = new RouteBuilder() { + public void configure() { + errorHandler(deadLetterChannel("mock:error")); + + from("direct:a") + .filter(header("foo").isEqualTo("bar")) + .to("direct:b"); + } +}; +------------------------------------------------------------- + +[[Routes-Choices]] +Choices +^^^^^^^ +With a choice you provide a list of predicates and outcomes along with an optional default otherwise clause which is invoked if none of the conditions are met. + +[source,java] +------------------------------------------------------------- +RouteBuilder builder = new RouteBuilder() { + public void configure() { + errorHandler(deadLetterChannel("mock:error")); + + from("direct:a") + .choice() + .when(header("foo").isEqualTo("bar")) + .to("direct:b") + .when(header("foo").isEqualTo("cheese")) + .to("direct:c") + .otherwise() + .to("direct:d"); + } +}; +------------------------------------------------------------- + +[[Routes-Using-a-custom-processor]] +Using a custom processor +^^^^^^^^^^^^^^^^^^^^^^^^ + +Here is an example of using a custom Processor +[source,java] +---------------------------------------------------------- +myProcessor = new Processor() { + public void process(Exchange exchange) { + log.debug("Called with exchange: " + exchange); + } +}; + +RouteBuilder builder = new RouteBuilder() { + public void configure() { + errorHandler(deadLetterChannel("mock:error")); + + from("direct:a") + .process(myProcessor); + } +}; +---------------------------------------------------------- + +You can mix and match custom processors with filters and choices. + +[source,java] +---------------------------------------------------------- +RouteBuilder builder = new RouteBuilder() { + public void configure() { + errorHandler(deadLetterChannel("mock:error")); + + from("direct:a") + .filter(header("foo").isEqualTo("bar")) + .process(myProcessor); + } +}; +---------------------------------------------------------- -- To stop receiving notification emails like this one, please contact ningji...@apache.org.