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 add8c2b Polish and cleanup documentation add8c2b is described below commit add8c2b3e0f7511374ea29d98a1e390b49380127 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Aug 12 12:06:16 2021 +0200 Polish and cleanup documentation --- docs/user-manual/modules/ROOT/pages/routes.adoc | 119 +++++---------------- .../modules/ROOT/pages/running-examples.adoc | 64 ----------- 2 files changed, 27 insertions(+), 156 deletions(-) diff --git a/docs/user-manual/modules/ROOT/pages/routes.adoc b/docs/user-manual/modules/ROOT/pages/routes.adoc index 06f9567..6fdb5088 100644 --- a/docs/user-manual/modules/ROOT/pages/routes.adoc +++ b/docs/user-manual/modules/ROOT/pages/routes.adoc @@ -1,56 +1,46 @@ [[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. +A Camel _route_ is where the integration flow is defined. +For example to integrate two systems then a Camel route can be _coded_ to specify how these systems are integrated. -For example a simple route can be created as follows. +An example could be to take files from a FTP server and send to a ActiveMQ messaging system. -[source,java] ------------------------------------------------------- -RouteBuilder builder = new RouteBuilder() { - public void configure() { - errorHandler(deadLetterChannel("mock:error")); - - from("direct:a").to("direct:b"); - } -}; ------------------------------------------------------- +This can be coded in a route using Java with the xref:java-dsl.adoc[Java DSL] -As you can see from the above Camel uses URIs to wire endpoints together. - -[[Routes-URI-String-Formatting]] -== URI String formatting +[source,java] +---- +from("ftp:myserver/folder") + .to("activemq:queue:cheese"); +---- -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. +Camel support coding in other languages such as XML: -[source,java] --------------------------------------------------------------------- -from("direct:start").toF("file://%s?fileName=%s", path, name); +[source,xml] +---- +<route> + <from uri="ftp:myserver/folder"/> + <to uri="activemq:queue:cheese"/> +</route> +---- -fromF("file://%s?include=%s", path, pattern).toF("mock:%s", result); --------------------------------------------------------------------- +== RouteBuilder with Java DSL -[[Routes-Filters]] -== Filters -You can combine simple routes with filters which can be arbitrary Predicate implementations. +When coding routes with the xref:java-dsl.adoc[Java DSL] then you would use a `RouteBuilder` classes where +you code the route in the `configure` method as shown: [source,java] -------------------------------------------------------------- +------------------------------------------------------ RouteBuilder builder = new RouteBuilder() { public void configure() { - errorHandler(deadLetterChannel("mock:error")); - - from("direct:a") - .filter(header("foo").isEqualTo("bar")) - .to("direct:b"); + from("direct:a").to("direct:b"); } }; -------------------------------------------------------------- +------------------------------------------------------ -[[Routes-Lambda]] -== Routes using Java lambda style +As you can see from the above Camel uses URIs to wire endpoints together. -*Since Camel 3.5* +=== Routes using Java lambda style Camel now supports to define Camel routes in Java DSL using Lambda style. This can be beneficial for microservices or serverless where you may want to quickly define a few routes. @@ -64,61 +54,6 @@ rb -> rb.from("kafka:cheese").to("jms:queue:foo"); There is a bit more to this as the lambda route must be coded in a Java method that returns an instance of `LambdaRouteBuilder`. See more at the xref:lambda-route-builder.adoc[LambdaRouteBuilder] documentation. -[[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 +== More Information -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); - } -}; ----------------------------------------------------------- +See xref:dsl.adoc[DSL] for a list of supported languages you can use for coding Camel routes. diff --git a/docs/user-manual/modules/ROOT/pages/running-examples.adoc b/docs/user-manual/modules/ROOT/pages/running-examples.adoc deleted file mode 100644 index 27d3024..0000000 --- a/docs/user-manual/modules/ROOT/pages/running-examples.adoc +++ /dev/null @@ -1,64 +0,0 @@ -= Running Examples - -== Before you start - -To run the demos with maven, you need to -http://maven.apache.org[download and install Apache Maven]. - -To test your Maven install, change directory to the examples directory -and type: - -[source,shell] ----- -mvn -v ----- - -You should see something like: - -[source,shell] ----- -camel-rider:/tmp/camel/examples$ mvn -v -Maven version: 3.0.3 ----- - -== Running the examples in Maven - -To run the xref:walk-through-an-example.adoc[first example] using Maven, -change directory to the example you want to run then issue the following -command: - -[source,shell] ----- -mvn exec:java ----- - -To run the other Spring-based examples such as the -xref:spring-example.adoc[Spring Example], use the -xref:camel-maven-plugin.adoc[Camel Maven Plugin]. For example: - -[source,shell] ----- -cd camel-example-spring -mvn camel:run ----- - -== Running the examples in your IDE - -In each example you can run the main() from your IDE. - -To create an IDEA project, run - -[source,shell] ----- -mvn idea:idea ----- - -If you are an Eclipse user, run - -[source,shell] ----- -mvn eclipse:eclipse ----- - -You should now be able to open the project(s) in your IDE and run any -main() method you wish.