Repository: camel Updated Branches: refs/heads/master 2df6d5b90 -> 9dd869b44
CAMEL-11786: Migrate docs to more correct ascii doc format Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9dd869b4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9dd869b4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9dd869b4 Branch: refs/heads/master Commit: 9dd869b441298777bf039699ec49d85a8dba620e Parents: 2df6d5b Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Sep 19 16:56:18 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Sep 19 16:56:18 2017 +0200 ---------------------------------------------------------------------- camel-core/src/main/docs/eips/bean-eip.adoc | 23 ++-- camel-core/src/main/docs/eips/choice-eip.adoc | 37 ++---- .../src/main/docs/eips/circuitBreaker-eip.adoc | 12 +- .../main/docs/eips/correlation-identifier.adoc | 23 ++-- .../main/docs/eips/customLoadBalancer-eip.adoc | 20 ++-- .../src/main/docs/eips/dead-letter-channel.adoc | 115 +++++++++--------- camel-core/src/main/docs/eips/delay-eip.adoc | 115 ++++++++++-------- .../src/main/docs/eips/dynamicRouter-eip.adoc | 59 +++------- camel-core/src/main/docs/eips/enrich-eip.adoc | 118 +++++++++---------- .../src/main/docs/eips/event-message.adoc | 58 ++++----- camel-core/src/main/docs/eips/filter-eip.adoc | 75 ++++-------- .../src/main/docs/eips/guaranteed-delivery.adoc | 32 ++--- 12 files changed, 287 insertions(+), 400 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/bean-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/bean-eip.adoc b/camel-core/src/main/docs/eips/bean-eip.adoc index 6090550..1f92d2e 100644 --- a/camel-core/src/main/docs/eips/bean-eip.adoc +++ b/camel-core/src/main/docs/eips/bean-eip.adoc @@ -4,10 +4,10 @@ The *bean:* EIP binds beans to Camel message exchanges. === URI Format -[source,java] ---------------------- +[source] +---- bean:beanID[?options] ---------------------- +---- Where *beanID* can be any string which is used to look up the bean in the link:registry.html[Registry] @@ -19,14 +19,14 @@ The Bean EIP supports 5 options which are listed below: [width="100%",cols="3,1m,6",options="header"] -|======================================================================= +|=== | Name | Java Type | Description | ref | String | Sets a reference to a bean to use | method | String | Sets the method name on the bean to use | beanType | String | Sets the Class of the bean | cache | Boolean | Caches the bean lookup to avoid lookup up bean on every usage. | multiParameterArray | Boolean | *Deprecated* Whether the message body is an array type. -|======================================================================= +|=== // eip options: END === Bean as endpoint @@ -49,7 +49,7 @@ component. Instead of specifying the bean explicitly as the endpoint (i.e. `to("bean:beanName")`) you can use the following syntax: [source,java] -------------------------------------------------------- +---- // Send message to the bean endpoint // and invoke method resolved using Bean Binding. from("direct:start").beanRef("beanName"); @@ -57,13 +57,13 @@ from("direct:start").beanRef("beanName"); // Send message to the bean endpoint // and invoke given method. from("direct:start").beanRef("beanName", "methodName"); -------------------------------------------------------- +---- Instead of passing name of the reference to the bean (so that Camel will lookup for it in the registry), you can specify the bean itself: [source,java] ---------------------------------------------------------------- +---- // Send message to the given bean instance. from("direct:start").bean(new ExampleBean()); @@ -72,7 +72,7 @@ from("direct:start").bean(new ExampleBean(), "methodName"); // Camel will create the instance of bean and cache it for you. from("direct:start").bean(ExampleBean.class); ---------------------------------------------------------------- +---- === Bean binding @@ -85,11 +85,6 @@ mechanisms in Camel. === See also -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] -* link:getting-started.html[Getting Started] - * link:class.html[Class] component * link:bean-binding.html[Bean Binding] * link:bean-integration.html[Bean Integration] http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/choice-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/choice-eip.adoc b/camel-core/src/main/docs/eips/choice-eip.adoc index 774595f..3a0fcc3 100644 --- a/camel-core/src/main/docs/eips/choice-eip.adoc +++ b/camel-core/src/main/docs/eips/choice-eip.adoc @@ -28,45 +28,40 @@ The following example shows how to route a request from an input *seda:a* endpoint to either *seda:b*, *seda:c* or *seda:d* depending on the evaluation of various link:predicate.html[Predicate] expressions -*Using the link:fluent-builders.html[Fluent Builders]* - [source,java] --------------------------------------------------------- +---- RouteBuilder builder = new RouteBuilder() { public void configure() { - errorHandler(deadLetterChannel("mock:error")); - from("direct:a") .choice() - .when(header("foo").isEqualTo("bar")) + .when(simple("${header.foo} == 'bar'")) .to("direct:b") - .when(header("foo").isEqualTo("cheese")) + .when(simple("${header.foo} == 'cheese'")) .to("direct:c") .otherwise() .to("direct:d"); } }; --------------------------------------------------------- +---- TIP: See link:why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html[Why can I not use when or otherwise in a Java Camel route] if you have problems with the Java DSL, accepting using `when` or `otherwise`. - -*Using the link:spring-xml-extensions.html[Spring XML Extensions]* +And the same example using XML: [source,xml] -------------------------------------------------------------------------------------------- -<camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring"> +---- +<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:a"/> <choice> <when> - <xpath>$foo = 'bar'</xpath> + <simple>${header.foo} == 'bar'</simple> <to uri="direct:b"/> </when> <when> - <xpath>$foo = 'cheese'</xpath> + <simple>${header.foo} == 'cheese'</simple> <to uri="direct:c"/> </when> <otherwise> @@ -75,17 +70,5 @@ problems with the Java DSL, accepting using `when` or `otherwise`. </choice> </route> </camelContext> -------------------------------------------------------------------------------------------- - -For further examples of this pattern in use you could look at the -http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java?view=markup[junit -test case] - -#=== Using This Pattern +---- -If you would like to use this EIP Pattern then please read the -link:getting-started.html[Getting Started], you may also find the -link:architecture.html[Architecture] useful particularly the description -of link:endpoint.html[Endpoint] and link:uris.html[URIs]. Then you could -try out some of the link:examples.html[Examples] first before trying -this pattern out. http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/circuitBreaker-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/circuitBreaker-eip.adoc b/camel-core/src/main/docs/eips/circuitBreaker-eip.adoc index e257bae..1660f6e 100644 --- a/camel-core/src/main/docs/eips/circuitBreaker-eip.adoc +++ b/camel-core/src/main/docs/eips/circuitBreaker-eip.adoc @@ -1,4 +1,5 @@ == 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. @@ -18,7 +19,7 @@ The Circuit Breaker EIP supports 3 options which are listed below: An example using Java DSL: [source,java] --------------------------------------------------------- +---- from("direct:start") .onException(RejectedExecutionException.class) .handled(true) @@ -28,11 +29,11 @@ from("direct:start") .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"/> @@ -49,8 +50,5 @@ And the same example using Spring XML: </loadBalance> </route> </camelContext> --------------------------------------------------------- - -=== Using This Pattern +---- -If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/correlation-identifier.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/correlation-identifier.adoc b/camel-core/src/main/docs/eips/correlation-identifier.adoc index d020eb8..931ab70 100644 --- a/camel-core/src/main/docs/eips/correlation-identifier.adoc +++ b/camel-core/src/main/docs/eips/correlation-identifier.adoc @@ -1,6 +1,5 @@ [[CorrelationIdentifier-CorrelationIdentifier]] -Correlation Identifier -^^^^^^^^^^^^^^^^^^^^^^ +== Correlation Identifier Camel supports the http://www.enterpriseintegrationpatterns.com/CorrelationIdentifier.html[Correlation @@ -34,31 +33,23 @@ The following example demonstrates using the Camel JMSMessageID as the Correlation Identifier within a request/reply pattern in the link:jms.html[JMS] component -*Using the link:fluent-builders.html[Fluent Builders]* +=== Samples [source,java] -------------------------------------------------------------------------------- +---- from("direct:start") - .to(ExchangePattern.InOut,"jms:queue:foo?useMessageIDAsCorrelationID=true") + .to(ExchangePattern.InOut, "jms:queue:foo?useMessageIDAsCorrelationID=true") .to("mock:result"); -------------------------------------------------------------------------------- +---- - - -**Using the link:spring-xml-extensions.html[Spring XML Extensions]** +And with XML: [source,xml] ------------------------------------------------------------------------------ <route> <from uri="direct:start"/> - <to uri="jms:queue:foo?useMessageIDAsCorrelationID=true" pattern="InOut"/> + <to pattern="InOut" uri="jms:queue:foo?useMessageIDAsCorrelationID=true"/> <to uri="mock:result"/> </route> ------------------------------------------------------------------------------ -[[CorrelationIdentifier-SeeAlso]] -See Also -++++++++ - -* link:bam.html[BAM] - http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/customLoadBalancer-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/customLoadBalancer-eip.adoc b/camel-core/src/main/docs/eips/customLoadBalancer-eip.adoc index 26a0d0c..02d6d86 100644 --- a/camel-core/src/main/docs/eips/customLoadBalancer-eip.adoc +++ b/camel-core/src/main/docs/eips/customLoadBalancer-eip.adoc @@ -1,6 +1,6 @@ == Custom Load Balancer EIP -You can use a custom load balancer (eg your own implementation) also. +You can use a custom load balancer (eg your own implementation) also. // eip options: START The Custom Load Balancer EIP supports 1 options which are listed below: @@ -16,16 +16,16 @@ The Custom Load Balancer EIP supports 1 options which are listed below: An example using Java DSL: [source,java] --------------------------------------------------------- +---- from("direct:start") // using our custom load balancer .loadBalance(new MyLoadBalancer()) .to("mock:x", "mock:y", "mock:z"); --------------------------------------------------------- +---- And the same example using XML DSL: [source,xml] --------------------------------------------------------- +---- <!-- this is the implementation of our custom load balancer --> <bean id="myBalancer" class="org.apache.camel.processor.CustomLoadBalanceTest$MyLoadBalancer"/> @@ -42,23 +42,23 @@ And the same example using XML DSL: </loadBalance> </route> </camelContext> --------------------------------------------------------- +---- -Notice in the XML DSL above we use <custom> which is only available in *Camel 2.8* onwards. In older releases you would have to do as follows instead: +Notice in the XML DSL above we use `<custom>` which is only available in *Camel 2.8* onwards. In older releases you would have to do as follows instead: [source,xml] --------------------------------------------------------- +---- <loadBalance ref="myBalancer"> <!-- these are the endpoints to balancer --> <to uri="mock:x"/> <to uri="mock:y"/> <to uri="mock:z"/> </loadBalance> --------------------------------------------------------- +---- To implement a custom load balancer you can extend some support classes such as `LoadBalancerSupport` and `SimpleLoadBalancerSupport`. The former supports the asynchronous routing engine, and the latter does not. Here is an example of a custom load balancer implementation: [source,java] --------------------------------------------------------- +---- public static class MyLoadBalancer extends LoadBalancerSupport { public boolean process(Exchange exchange, AsyncCallback callback) { @@ -78,4 +78,4 @@ public static class MyLoadBalancer extends LoadBalancerSupport { return true; } } --------------------------------------------------------- +---- http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/dead-letter-channel.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/dead-letter-channel.adoc b/camel-core/src/main/docs/eips/dead-letter-channel.adoc index 4e96819..32981d3 100644 --- a/camel-core/src/main/docs/eips/dead-letter-channel.adoc +++ b/camel-core/src/main/docs/eips/dead-letter-channel.adoc @@ -10,12 +10,6 @@ processor which is an link:error-handler.html[Error Handler]. image:http://www.enterpriseintegrationpatterns.com/img/DeadLetterChannelSolution.gif[image] -TIP:*Difference between Dead Letter Channel and Default Error -Handler* - -The Default Error Handler does very little: it ends the Exchange -immediately and propagates the thrown Exception back to the caller. - The Dead Letter Channel lets you control behaviors including redelivery, whether to propagate the thrown Exception to the caller (the *handled* option), and where the (failed) Exchange should now be routed to. @@ -39,6 +33,10 @@ error handler). When a new Exception occurs then the dead letter channel logs this at WARN level. This can be turned off by setting logNewException=false. +TIP: *Difference between Dead Letter Channel and Default Error +Handler* The Default Error Handler does very little: it ends the Exchange +immediately and propagates the thrown Exception back to the caller. + [[DeadLetterChannel-Redelivery]] === Redelivery @@ -80,18 +78,16 @@ link:exchange.html[Exchange]. For instance configuring the dead letter channel as: -*Using the link:fluent-builders.html[Fluent Builders]* - [source,java] ---------------------------------------------------- +---- errorHandler(deadLetterChannel("jms:queue:dead") .maximumRedeliveries(3).redeliveryDelay(5000)); ---------------------------------------------------- +---- -*Using the link:spring-xml-extensions.html[Spring XML Extensions]* +And in XML: [source,xml] ----------------------------------------------------------------------------------------------- +---- <route errorHandlerRef="myDeadLetterErrorHandler"> ... </route> @@ -105,7 +101,7 @@ errorHandler(deadLetterChannel("jms:queue:dead") <property name="maximumRedeliveries" value="3"/> <property name="redeliveryDelay" value="5000"/> </bean> ----------------------------------------------------------------------------------------------- +---- The link:dead-letter-channel.html[Dead Letter Channel] above will clear the caused exception (`setException(null)`), by moving the caused @@ -115,9 +111,7 @@ is moved to the `"jms:queue:dead"` destination and the client will not notice the failure. [[DeadLetterChannel-AboutmovingExchangetodeadletterqueueandusingtheoriginalmessage]] -About moving Exchange to dead letter queue and using the original -message -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Moving Exchange to dead letter queue and using the original message The option *useOriginalMessage* is used for routing the original input message instead of the current message that potentially is modified @@ -126,12 +120,12 @@ during routing. For instance if you have this route: [source,java] ---------------------------------- - from("jms:queue:order:input") - .to("bean:validateOrder") - .to("bean:transformOrder") - .to("bean:handleOrder"); ---------------------------------- +----- +from("jms:queue:order:input") + .to("bean:validateOrder") + .to("bean:transformOrder") + .to("bean:handleOrder"); +----- The route listen for JMS messages and validates, transforms and handle it. During this the link:exchange.html[Exchange] payload is @@ -146,11 +140,11 @@ input message we received from `jms:queue:order:input`. So we can do this by enabling the *useOriginalMessage* option as shown below: [source,java] -------------------------------------------------------------------------- - // will use original body - errorHandler(deadLetterChannel("jms:queue:dead") - .useOriginalMessage().maximumRedeliveries(5).redeliverDelay(5000); -------------------------------------------------------------------------- +---- +// will use original body +errorHandler(deadLetterChannel("jms:queue:dead") + .useOriginalMessage().maximumRedeliveries(5).redeliverDelay(5000); +---- Then the messages routed to the `jms:queue:dead` is the original input. If we want to manually retry we can move the JMS message from the failed @@ -166,7 +160,7 @@ that is executed just *before* every redelivery attempt. This can be used for the situations where you need to alter the message before its redelivered. See below for sample. -TIP:*onException and onRedeliver* +TIP: *onException and onRedeliver* We also support for per link:exception-clause.html[*onException*] to set a *onRedeliver*. That means you can do special on redelivery for different exceptions, as opposed to onRedelivery set on @@ -199,19 +193,16 @@ The maximum redeliver delay ensures that a delay is never longer than the value, default 1 minute. This can happen if you turn on the exponential backoff. -The maximum redeliveries is the number of *re* delivery attempts. By +The maximum redeliveries is the number of redelivery attempts. By default Camel will try to process the exchange 1 + 5 times. 1 time for -the normal attempt and then 5 attempts as redeliveries. + - Setting the maximumRedeliveries to a negative value such as -1 will -then always redelivery (unlimited). + - Setting the maximumRedeliveries to 0 will disable any re delivery -attempt. +the normal attempt and then 5 attempts as redeliveries. +Setting the maximumRedeliveries to a negative value such as -1 will +then always redelivery (unlimited). Setting the maximumRedeliveries to 0 +will disable any redelivery attempt. Camel will log delivery failures at the DEBUG logging level by default. You can change this by specifying retriesExhaustedLogLevel and/or -retryAttemptedLogLevel. See -http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java[ExceptionBuilderWithRetryLoggingLevelSetTest] -for an example. +retryAttemptedLogLevel. You can turn logging of stack traces on/off. If turned off Camel will still log the redelivery attempt. Its just much less verbose. @@ -301,9 +292,9 @@ link:exchange.html[Exchange] with a property that contains the *last* endpoint Camel send the link:exchange.html[Exchange] to: [source,java] ----------------------------------------------------------------------------------- +---- String lastEndpointUri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class); ----------------------------------------------------------------------------------- +---- The `Exchange.TO_ENDPOINT` have the constant value `CamelToEndpoint`. @@ -317,9 +308,9 @@ dead letter queue, then Camel also decorates the Exchange with another property that contains that *last* endpoint: [source,java] ------------------------------------------------------------------------------------------ +---- String failedEndpointUri = exchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class); ------------------------------------------------------------------------------------------ +---- The `Exchange.FAILURE_ENDPOINT` have the constant value `CamelFailureEndpoint`. @@ -330,17 +321,17 @@ letter queue and use that for error reporting. + link:recipient-list.html[Recipient List] so you know which endpoints failed. -*Notice:* These information is kept on the Exchange even if the message +These information is kept on the Exchange even if the message was successfully processed by a given endpoint, and then later fails for example in a local link:bean.html[Bean] processing instead. So beware that this is a hint that helps pinpoint errors. [source,java] -------------------------------------- +---- from("activemq:queue:foo") .to("http://someserver/somepath") .beanRef("foo"); -------------------------------------- +---- Now suppose the route above and a failure happens in the `foo` bean. Then the `Exchange.TO_ENDPOINT` and `Exchange.FAILURE_ENDPOINT` will @@ -357,33 +348,33 @@ adding information why the Exchange failed. For example the following processor adds a header with the exception message [source,java] ------------------------------------------------------------------------------------------------ - public static class MyPrepareProcessor implements Processor { - @Override - public void process(Exchange exchange) throws Exception { - Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); - exchange.getIn().setHeader("FailedBecause", cause.getMessage()); - } +---- +public static class MyPrepareProcessor implements Processor { + @Override + public void process(Exchange exchange) throws Exception { + Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); + exchange.getIn().setHeader("FailedBecause", cause.getMessage()); } ------------------------------------------------------------------------------------------------ +} +---- Then configure the error handler to use the processor as follows: [source,java] ---------------------------------------------------------------------------------------- +---- errorHandler(deadLetterChannel("jms:dead").onPrepareFailure(new MyPrepareProcessor())); ---------------------------------------------------------------------------------------- +---- Configuring this from XML DSL is as shown: -[source,java] --------------------------------------------------------------------------------------------------------------- - <bean id="myPrepare" - class="org.apache.camel.processor.DeadLetterChannelOnPrepareTest.MyPrepareProcessor"/> +[source,xml] +---- +<bean id="myPrepare" + class="org.apache.camel.processor.DeadLetterChannelOnPrepareTest.MyPrepareProcessor"/> - <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/> --------------------------------------------------------------------------------------------------------------- +<errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/> +---- The onPrepare is also available using the default error handler. @@ -400,9 +391,9 @@ Camel will decorate + occurred. [source,java] -------------------------------------------------------------------------------------- +---- String failedRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class); -------------------------------------------------------------------------------------- +---- The `Exchange.FAILURE_ROUTE_ID` have the constant value `CamelFailureRouteId`. http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/delay-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/delay-eip.adoc b/camel-core/src/main/docs/eips/delay-eip.adoc index 8eae05b..9051663 100644 --- a/camel-core/src/main/docs/eips/delay-eip.adoc +++ b/camel-core/src/main/docs/eips/delay-eip.adoc @@ -1,21 +1,6 @@ == Delay EIP The Delayer Pattern allows you to delay the delivery of messages to some destination. -[NOTE] -==== -The expression is a value in millis to wait from the current time, so the expression should just be 3000. - -However you can use a long value for a fixed value to indicate the delay in millis. - -See the Spring DSL samples for Delayer. -==== - -[WARNING] -.Using Delayer in Java DSL -==== -See this ticket: link:https://issues.apache.org/jira/browse/CAMEL-2654[https://issues.apache.org/jira/browse/CAMEL-2654] -==== - == Options // eip options: START @@ -31,47 +16,72 @@ The Delay EIP supports 3 options which are listed below: |======================================================================= // eip options: END -*Using the Fluent Builders* +[NOTE] +==== +The expression is a value in millis to wait from the current time, so the expression should just be 3000. + +However you can use a long value for a fixed value to indicate the delay in millis. + +See the Spring DSL samples for Delayer. +==== + +[CAUTION] +.Using Delayer in Java DSL +==== +See this ticket: link:https://issues.apache.org/jira/browse/CAMEL-2654[https://issues.apache.org/jira/browse/CAMEL-2654] +==== + +=== Samples + The example below will delay all messages received on *seda:b* 1 second before sending them to *mock:result*. [source,java] --------------------------------------------------------- -from("seda:b").delay(1000).to("mock:result"); --------------------------------------------------------- +---- +from("seda:b") + .delay(1000) + .to("mock:result"); +---- You can just delay things a fixed amount of time from the point at which the delayer receives the message. For example to delay things 2 seconds [source,java] --------------------------------------------------------- +---- delayer(2000) --------------------------------------------------------- +---- The above assume that the delivery order is maintained and that the messages are delivered in delay order. If you want to reorder the messages based on delivery time, you can use the Resequencer with this pattern. For example [source,java] --------------------------------------------------------- -from("activemq:someQueue").resequencer(header("MyDeliveryTime")).delay("MyRedeliveryTime").to("activemq:aDelayedQueue"); --------------------------------------------------------- +---- +from("activemq:someQueue") + .resequencer(header("MyDeliveryTime")) + .delay("MyRedeliveryTime") + .to("activemq:aDelayedQueue"); +---- You can of course use many different Expression languages such as XPath, XQuery, SQL or various Scripting Languages. For example to delay the message for the time period specified in the header, use the following syntax: [source,java] --------------------------------------------------------- -from("activemq:someQueue").delay(header("delayValue")).to("activemq:aDelayedQueue"); --------------------------------------------------------- +---- +from("activemq:someQueue") + .delay(header("delayValue")) + .to("activemq:aDelayedQueue"); +---- And to delay processing using the Simple language you can use the following DSL: [source,java] --------------------------------------------------------- -from("activemq:someQueue").delay(simple("${body.delayProperty}")).to("activemq:aDelayedQueue"); --------------------------------------------------------- +---- +from("activemq:someQueue") + .delay(simple("${body.delayProperty}")) + .to("activemq:aDelayedQueue"); +---- -== Spring DSL +==== Spring DSL The sample below demonstrates the delay in Spring DSL: [source,xml] --------------------------------------------------------- +---- <bean id="myDelayBean" class="org.apache.camel.processor.MyDelayCalcBean"/> <bean id="exchangeAwareBean" class="org.apache.camel.processor.ExchangeAwareDelayCalcBean"/> @@ -105,27 +115,30 @@ The sample below demonstrates the delay in Spring DSL: <to uri="mock:result"/> </route> </camelContext> --------------------------------------------------------- +---- -For further examples of this pattern in use you could look at the link:http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java?view=markup[junit test case]. +=== Asynchronous delaying -== Asynchronous delaying *Available as of Camel 2.4* + You can let the Delayer use non blocking asynchronous delaying, which means Camel will use a scheduler to schedule a task to be executed in the future. The task will then continue routing. This allows the caller thread to not block and be able to service other messages etc. -=== From Java DSL +==== From Java DSL You use the `asyncDelayed()` to enable the async behavior. [source,java] --------------------------------------------------------- -from("activemq:queue:foo").delay(1000).asyncDelayed().to("activemq:aDelayedQueue"); --------------------------------------------------------- +---- +from("activemq:queue:foo") + .delay(1000).asyncDelayed() + .to("activemq:aDelayedQueue"); +---- + +==== From Spring XML -=== From Spring XML You use the `asyncDelayed="true"` attribute to enable the async behavior. [source,xml] --------------------------------------------------------- +---- <route> <from uri="activemq:queue:foo"/> <delay asyncDelayed="true"> @@ -133,22 +146,23 @@ You use the `asyncDelayed="true"` attribute to enable the async behavior. </delay> <to uri="activemq:aDealyedQueue"/> </route> --------------------------------------------------------- +---- === Creating a custom delay -You can use an expression to determine when to send a message using something like this + +You can use an expression, such as calling a method on a bean, to determine when to send a message using something like this [source,java] --------------------------------------------------------- +---- from("activemq:foo"). delay().method("someBean", "computeDelay"). to("activemq:bar"); --------------------------------------------------------- +---- then the bean would look like this... [source,java] --------------------------------------------------------- +---- public class SomeBean { public long computeDelay() { long delay = 0; @@ -156,10 +170,9 @@ public class SomeBean { return delay; } } --------------------------------------------------------- +---- + -== Using This Pattern -If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. +=== See Also -== See Also -Delay Interceptor +- Delay Interceptor http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/dynamicRouter-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/dynamicRouter-eip.adoc b/camel-core/src/main/docs/eips/dynamicRouter-eip.adoc index 96a80fc..bbc4290 100644 --- a/camel-core/src/main/docs/eips/dynamicRouter-eip.adoc +++ b/camel-core/src/main/docs/eips/dynamicRouter-eip.adoc @@ -1,12 +1,13 @@ == Dynamic Router EIP + The link:http://www.enterpriseintegrationpatterns.com/DynamicRouter.html[Dynamic Router] from the link:../../../../readme-eip.adoc[EIP patterns] allows you to route messages while avoiding the dependency of the router on all possible destinations while maintaining its efficiency. image:http://www.enterpriseintegrationpatterns.com/img/DynamicRouter.gif[image] In *Camel 2.5* we introduced a dynamicRouter in the DSL which is like a dynamic Routing Slip which evaluates the slip _on-the-fly_. -[WARNING] -.Beware +[IMPORTANT] +.Avoid endless looping ==== You must ensure the expression used for the `dynamicRouter` such as a bean, will return `null` to indicate the end. Otherwise the `dynamicRouter` will keep repeating endlessly. ==== @@ -26,23 +27,24 @@ The Dynamic Router EIP supports 3 options which are listed below: |======================================================================= // eip options: END -== Dynamic Router in Camel 2.5 onwards -From Camel 2.5 the Dynamic Router will set a property (Exchange.SLIP_ENDPOINT) on the Exchange which contains the current endpoint as it advanced though the slip. This allows you to know how far we have processed in the slip. (It's a slip because the Dynamic Router implementation is based on top of Routing Slip). +The Dynamic Router will set the property `Exchange.SLIP_ENDPOINT` on the Exchange which contains the current endpoint as it advanced though the slip. This allows you to know how far we have processed in the slip. +(It's a slip because the Dynamic Router implementation is based on top of Routing Slip). + +=== Samples -=== Java DSL In Java DSL you can use the `dynamicRouter` as shown below: [source,java] --------------------------------------------------------- +---- from("direct:start") // use a bean as the dynamic router .dynamicRouter(method(DynamicRouterTest.class, "slip")); --------------------------------------------------------- +---- Which will leverage a Bean to compute the slip _on-the-fly_, which could be implemented as follows: [source,java] --------------------------------------------------------- +---- /** * Use this method to compute dynamic where we should route next. * @@ -66,12 +68,12 @@ public String slip(String body) { // no more so return null return null; } --------------------------------------------------------- +---- Mind that this example is only for show and tell. The current implementation is not thread safe. You would have to store the state on the Exchange, to ensure thread safety, as shown below: [source,java] --------------------------------------------------------- +---- /** * Use this method to compute dynamic where we should route next. * @@ -106,7 +108,7 @@ public String slip(String body, @Properties Map<String, Object> properties) { // no more so return null return null; } --------------------------------------------------------- +---- You could also store state as message headers, but they are not guaranteed to be preserved during routing, where as properties on the Exchange are. Although there was a bug in the method call expression, see the warning below. @@ -116,11 +118,11 @@ You could also store state as message headers, but they are not guaranteed to be Mind that in Camel 2.9.2 or older, when using a Bean the state is not propagated, so you will have to use a Processor instead. This is fixed in Camel 2.9.3 onwards. ==== -=== Spring XML +==== Spring XML The same example in Spring XML would be: [source,xml] --------------------------------------------------------- +---- <bean id="mySlip" class="org.apache.camel.processor.DynamicRouterTest"/> <camelContext xmlns="http://camel.apache.org/schema/spring"> @@ -138,14 +140,14 @@ The same example in Spring XML would be: </route> </camelContext> --------------------------------------------------------- +---- === @DynamicRouter annotation You can also use the `@DynamicRouter` annotation, for example the Camel 2.4 example below could be written as follows. The `route` method would then be invoked repeatedly as the message is processed dynamically. The idea is to return the next endpoint uri where to go. Return `null` to indicate the end. You can return multiple endpoints if you like, just as the Routing Slip, where each endpoint is separated by a delimiter. [source,java] --------------------------------------------------------- +---- public class MyDynamicRouter { @Consume(uri = "activemq:foo") @@ -155,30 +157,5 @@ public class MyDynamicRouter { // return the next endpoint uri, where to go. Return null to indicate the end. } } --------------------------------------------------------- - -== Dynamic Router in Camel 2.4 or older -The simplest way to implement this is to use the RecipientList Annotation on a Bean method to determine where to route the message. - -[source,java] --------------------------------------------------------- -public class MyDynamicRouter { - - @Consume(uri = "activemq:foo") - @RecipientList - public List<String> route(@XPath("/customer/id") String customerId, @Header("Location") String location, Document body) { - // query a database to find the best match of the endpoint based on the input parameteres - ... - } -} --------------------------------------------------------- - -In the above we can use the Parameter Binding Annotations to bind different parts of the Message to method parameters or use an Expression such as using XPath or XQuery. -The method can be invoked in a number of ways as described in the Bean Integration such as - -* POJO Producing -* Spring Remoting -* Bean component +---- -== Using This Pattern -If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/enrich-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/enrich-eip.adoc b/camel-core/src/main/docs/eips/enrich-eip.adoc index 85eaa9c..1948940 100644 --- a/camel-core/src/main/docs/eips/enrich-eip.adoc +++ b/camel-core/src/main/docs/eips/enrich-eip.adoc @@ -1,62 +1,59 @@ == Enrich EIP + Camel supports the Content Enricher from the EIP patterns using a Message Translator, an arbitrary Processor in the routing logic, or using the enrich DSL element to enrich the message. image:http://www.enterpriseintegrationpatterns.com/img/DataEnricher.gif[image] === Content enrichment using a Message Translator or a Processor -*Using the Fluent Builders* You can use Templating to consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination. For example using InOnly (one way messaging) +=== Samples + [source,java] --------------------------------------------------------- +---- from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"). to("activemq:Another.Queue"); --------------------------------------------------------- +---- If you want to use InOut (request-reply) semantics to process requests on the *My.Queue* queue on ActiveMQ with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this: [source,java] --------------------------------------------------------- +---- from("activemq:My.Queue"). to("velocity:com/acme/MyResponse.vm"); --------------------------------------------------------- +---- Here is a simple example using the DSL directly to transform the message body [source,java] --------------------------------------------------------- +---- from("direct:start").setBody(body().append(" World!")).to("mock:result"); --------------------------------------------------------- +---- In this example we add our own Processor using explicit Java code [source,java] --------------------------------------------------------- +---- from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + " World!"); } }).to("mock:result"); --------------------------------------------------------- +---- Finally we can use Bean Integration to use any Java method on any bean to act as the transformer [source,java] --------------------------------------------------------- +---- from("activemq:My.Queue"). beanRef("myBeanName", "myMethodName"). to("activemq:Another.Queue"); --------------------------------------------------------- - -For further examples of this pattern in use you could look at one of the JUnit tests - -* TransformTest -* TransformViaDSLTest +---- -*Using Spring XML* +==== Using Spring XML [source,xml] -------------------------------------------------------- @@ -92,7 +89,7 @@ From *Camel 2.16* onwards both `enrich` and `pollEnrich` supports dynamic endpoi === Enrich Options [width="100%",cols="3,2,6",options="header"] -|======================================================================= +|=== | Option | Default Value | Description | `uri` | | The endpoint uri for the external service to enrich from. You must use either uri or ref. *Important:* From Camel 2.16 onwards, this option is removed, and you use an Expression to configure the uri, such as Simple or Constant or any other dynamic language that can compute the uri dynamically using values from the current Exchange. | `ref` | | Refers to the endpoint for the external service to enrich from. You must use either `uri` or `ref`. *Important:* From *Camel 2.16* onwards, this option is removed, and you use an Expression to configure the uri, such as Simple or Constant or any other dynamic language that can compute the uri dynamically using values from the current Exchange. @@ -104,28 +101,28 @@ From *Camel 2.16* onwards both `enrich` and `pollEnrich` supports dynamic endpoi | `shareUnitOfWork` | `false` | *Camel 2.16*: Shares the unit of work with the parent and the resource exchange. Enrich will by default not share unit of work between the parent exchange and the resource exchange. This means the resource exchange has its own individual unit of work. See Splitter for more information and example. | `cacheSize` | | *Camel 2.16*: Allows to configure the cache size for the ProducerCache which caches producers for reuse in the enrich. Will by default use the default cache size which is 1000. Setting the value to -1 allows to turn off the cache all together. | `ignoreInvalidEndpoint` | false | *Camel 2.16*: Whether to ignore an endpoint URI that could not be resolved. If disabled, Camel will throw an exception identifying the invalid endpoint URI. -|======================================================================= +|=== -*Using the Fluent Builders* +A little enrich example using Java: [source,java] --------------------------------------------------------- +---- AggregationStrategy aggregationStrategy = ... from("direct:start") -.enrich("direct:resource", aggregationStrategy) -.to("direct:result"); + .enrich("direct:resource", aggregationStrategy) + .to("direct:result"); from("direct:resource") ... --------------------------------------------------------- +---- The content enricher (`enrich`) retrieves additional data from a _resource endpoint_ in order to enrich an incoming message (contained in the _original exchange_). An aggregation strategy is used to combine the original exchange and the _resource exchange_. The first parameter of the `AggregationStrategy.aggregate(Exchange, Exchange)` method corresponds to the the original exchange, the second parameter the resource exchange. The results from the resource endpoint are stored in the resource exchange's out-message. Here's an example template for implementing an aggregation strategy: [source,java] --------------------------------------------------------- +---- public class ExampleAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange original, Exchange resource) { @@ -141,14 +138,16 @@ public class ExampleAggregationStrategy implements AggregationStrategy { } } --------------------------------------------------------- +---- Using this template the original exchange can be of any pattern. The resource exchange created by the enricher is always an in-out exchange. -*Using Spring XML* +==== Enrich example using XML + The same example in the Spring DSL (Camel 2.15 or older) + [source,xml] --------------------------------------------------------- +---- <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> @@ -162,11 +161,11 @@ The same example in the Spring DSL (Camel 2.15 or older) </camelContext> <bean id="aggregationStrategy" class="..." /> --------------------------------------------------------- +---- The same example in the Spring DSL (Camel 2.16 or newer) [source,xml] --------------------------------------------------------- +---- <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> @@ -182,31 +181,31 @@ The same example in the Spring DSL (Camel 2.16 or newer) </camelContext> <bean id="aggregationStrategy" class="..." /> --------------------------------------------------------- +---- === Aggregation strategy is optional The aggregation strategy is optional. If you do not provide it Camel will by default just use the body obtained from the resource. [source,java] --------------------------------------------------------- +---- from("direct:start") .enrich("direct:resource") .to("direct:result"); --------------------------------------------------------- +---- In the route above the message sent to the direct:result endpoint will contain the output from the direct:resource as we do not use any custom aggregation. And for Spring DSL (Camel 2.15 or older) just omit the strategyRef attribute: [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <enrich uri="direct:resource"/> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- And for Spring DSL (Camel 2.16 or newer) just omit the strategyRef attribute: [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <enrich> @@ -214,21 +213,22 @@ And for Spring DSL (Camel 2.16 or newer) just omit the strategyRef attribute: </enrich> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- === Using dynamic uris *Available as of Camel 2.16* + From Camel 2.16 onwards `enrich` and `pollEnrich` supports using dynamic uris computed based on information from the current Exchange. For example to enrich from a HTTP endpoint where the header with key orderId is used as part of the content-path of the HTTP url: [source,java] --------------------------------------------------------- +---- from("direct:start") .enrich().simple("http:myserver/${header.orderId}/order") .to("direct:result"); --------------------------------------------------------- +---- And in XML DSL [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <enrich> @@ -236,9 +236,9 @@ And in XML DSL </enrich> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- -=== Content enrichment using `pollEnrich` +=== Content enrichment using pollEnrich The `pollEnrich` works just as the `enrich` however as it uses a Polling Consumer we have 3 methods when polling * `receive` @@ -287,29 +287,29 @@ The timeout values is in millis. From *Camel 2.16* onwards both `enrich` and `pollEnrich` supports dynamic endpoints that uses an Expression to compute the uri, which allows to use data from the current Exchange. In other words all what is told above no longer apply and it just works. ==== -=== Example +=== PollEnrich Example In this example we enrich the message by loading the content from the file named inbox/data.txt. [source,java] --------------------------------------------------------- +---- from("direct:start") .pollEnrich("file:inbox?fileName=data.txt") .to("direct:result"); --------------------------------------------------------- +---- And in XML DSL (Camel 2.15 or older) you do: [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <pollEnrich uri="file:inbox?fileName=data.txt"/> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- And in XML DSL (Camel 2.16 or newer) you do: [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <pollEnrich> @@ -317,23 +317,23 @@ And in XML DSL (Camel 2.16 or newer) you do: </pollEnrich> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- If there is no file then the message is empty. We can use a timeout to either wait (potentially forever) until a file exists, or use a timeout to wait a certain period. For example to wait up to 5 seconds you can do (Camel 2.15 or older): [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <pollEnrich uri="file:inbox?fileName=data.txt" timeout="5000"/> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- For example to wait up to 5 seconds you can do (Camel 2.16 or newer): [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <pollEnrich timeout="5000"> @@ -341,21 +341,23 @@ For example to wait up to 5 seconds you can do (Camel 2.16 or newer): </pollEnrich> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- === Using dynamic uris + *Available as of Camel 2.16* + From Camel 2.16 onwards `enrich` and `pollEnrich` supports using dynamic uris computed based on information from the current Exchange. For example to `pollEnrich` from an endpoint that uses a header to indicate a SEDA queue name: [source,java] --------------------------------------------------------- +---- from("direct:start") .pollEnrich().simple("seda:${header.name}") .to("direct:result"); --------------------------------------------------------- +---- And in XML DSL [source,xml] --------------------------------------------------------- +---- <route> <from uri="direct:start"/> <pollEnrich> @@ -363,7 +365,5 @@ And in XML DSL </pollEnrich> <to uri="direct:result"/> </route> --------------------------------------------------------- +---- -=== Using This Pattern -If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/event-message.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/event-message.adoc b/camel-core/src/main/docs/eips/event-message.adoc index a25cf8f..37226ca 100644 --- a/camel-core/src/main/docs/eips/event-message.adoc +++ b/camel-core/src/main/docs/eips/event-message.adoc @@ -1,6 +1,5 @@ [[EventMessage-EventMessage]] -Event Message -~~~~~~~~~~~~~ +== Event Message Camel supports the http://www.enterpriseintegrationpatterns.com/EventMessage.html[Event @@ -16,71 +15,56 @@ The default behaviour of many link:components.html[Components] is InOnly such as for link:jms.html[JMS], link:file2.html[File] or link:seda.html[SEDA] -[TIP] -==== -*Related* - -See the related link:request-reply.html[Request Reply] message. -==== +TIP: See the related link:request-reply.html[Request Reply] message. [[EventMessage-ExplicitlyspecifyingInOnly]] -Explicitly specifying InOnly -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Explicitly specifying InOnly If you are using a component which defaults to InOut you can override the link:exchange-pattern.html[Exchange Pattern] for an endpoint using the pattern property. -[source,java] ------------------------------- +[source] +---- foo:bar?exchangePattern=InOnly ------------------------------- +---- + + +=== Samples From 2.0 onwards on Camel you can specify the link:exchange-pattern.html[Exchange Pattern] using the DSL. -*Using the link:fluent-builders.html[Fluent Builders]* - [source,java] ---------------------------------------------- +---- from("mq:someQueue"). setExchangePattern(ExchangePattern.InOnly). bean(Foo.class); ---------------------------------------------- +---- or you can invoke an endpoint with an explicit pattern [source,java] ----------------------------- +---- from("mq:someQueue"). inOnly("mq:anotherQueue"); ----------------------------- +---- -*Using the link:spring-xml-extensions.html[Spring XML Extensions]* +And with XML: -[source,java] ------------------------------- +[source,xml] +---- <route> <from uri="mq:someQueue"/> <inOnly uri="bean:foo"/> </route> ------------------------------- +---- -[source,java] ------------------------------------ +[source,xml] +---- <route> <from uri="mq:someQueue"/> <inOnly uri="mq:anotherQueue"/> </route> ------------------------------------ - -[[EventMessage-UsingThisPattern]] -Using This Pattern -++++++++++++++++++ - -If you would like to use this EIP Pattern then please read the -link:getting-started.html[Getting Started], you may also find the -link:architecture.html[Architecture] useful particularly the description -of link:endpoint.html[Endpoint] and link:uris.html[URIs]. Then you could -try out some of the link:examples.html[Examples] first before trying -this pattern out. +---- + http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/filter-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/filter-eip.adoc b/camel-core/src/main/docs/eips/filter-eip.adoc index e778254..c4db1ab 100644 --- a/camel-core/src/main/docs/eips/filter-eip.adoc +++ b/camel-core/src/main/docs/eips/filter-eip.adoc @@ -1,5 +1,4 @@ == Filter EIP -=== Message Filter The http://www.enterpriseintegrationpatterns.com/Filter.html[Message Filter] from the link:enterprise-integration-patterns.html[EIP patterns] @@ -17,59 +16,48 @@ link:predicate.html[Predicate] is true will be dispatched to *queue:b* The Filter EIP supports 0 options which are listed below: // eip options: END +=== Samples -*Using the link:fluent-builders.html[Fluent Builders]* +Here is a little example in Java DSL: [source,java] ----------------------------------------------------------------------------- -RouteBuilder builder = new RouteBuilder() { - public void configure() { - errorHandler(deadLetterChannel("mock:error")); - - from("direct:a") - .filter(header("foo").isEqualTo("bar")) - .to("direct:b"); - } -}; ----------------------------------------------------------------------------- - -You can, of course, use many different link:predicate.html[Predicate] -languages such as link:xpath.html[XPath], link:xquery.html[XQuery], -link:sql.html[SQL] or various link:scripting-languages.html[Scripting -Languages]. Here is an -http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java[XPath -example] +---- +from("direct:a") + .filter(simple("${header.foo} == 'bar'")) + .to("direct:b"); +---- +You can use many different languages as the predicate, such as XPath: [source,java] ----------------------------------------------------------------------------- +---- from("direct:start"). - filter().xpath("/person[@name='James']"). + filter().xpath("/person[@name='James']"). to("mock:result"); ----------------------------------------------------------------------------- +---- Here is another example of using a bean to define the filter behavior [source,java] ----------------------------------------------------------------------------- +---- from("direct:start") - .filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end() - .to("mock:end"); + .filter().method(MyBean.class, "isGoldCustomer") + .to("mock:gold") + .end() + .to("mock:all"); public static class MyBean { public boolean isGoldCustomer(@Header("level") String level) { return level.equals("gold"); } } ----------------------------------------------------------------------------- +---- -*Using the link:spring-xml-extensions.html[Spring XML Extensions]* - -You can also use a method call expression (to call a method on a bean) -in the Message Filter, as shown below: +And the example in XML: [source,xml] ----------------------------------------------------------------------------- +---- <bean id="myBean" class="com.foo.MyBean"/> + <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:a"/> @@ -79,18 +67,10 @@ in the Message Filter, as shown below: </filter> </route> </camelContext> ----------------------------------------------------------------------------- +---- -INFO:make sure you put the endpoint you want to filter (<to uri="seda:b"/>, -etc.) before the closing </filter> tag or the filter will not be applied -(in 2.8+, omitting this will result in an error) - -For further examples of this pattern in use you could look at the -http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java?view=markup[junit -test case] - -#=== *Using stop* +=== Using stop Stop is a bit different than a message filter as it will filter out all messages and end the route entirely (filter only applies to its child @@ -102,7 +82,7 @@ In the example below we do not want to route messages any further that has the word `Bye` in the message body. Notice how we prevent this in the when predicate by using the `.stop()`. -#=== Knowing if link:exchange.html[Exchange] was filtered or not +=== Knowing if Exchange was filtered or not *Available as of Camel 2.5* @@ -119,12 +99,3 @@ steps immediately following the link:message-filter.html[Message Filter] with the value set based on the results of the last link:message-filter.html[Message Filter] link:predicate.html[Predicate] evaluated. - -#=== Using This Pattern - -If you would like to use this EIP Pattern then please read the -link:getting-started.html[Getting Started], you may also find the -link:architecture.html[Architecture] useful particularly the description -of link:endpoint.html[Endpoint] and link:uris.html[URIs]. Then you could -try out some of the link:examples.html[Examples] first before trying -this pattern out. http://git-wip-us.apache.org/repos/asf/camel/blob/9dd869b4/camel-core/src/main/docs/eips/guaranteed-delivery.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/guaranteed-delivery.adoc b/camel-core/src/main/docs/eips/guaranteed-delivery.adoc index 7620c9b..7fe4fd5 100644 --- a/camel-core/src/main/docs/eips/guaranteed-delivery.adoc +++ b/camel-core/src/main/docs/eips/guaranteed-delivery.adoc @@ -1,6 +1,5 @@ [[GuaranteedDelivery-GuaranteedDelivery]] -Guaranteed Delivery -^^^^^^^^^^^^^^^^^^^ +== Guaranteed Delivery Camel supports the http://www.enterpriseintegrationpatterns.com/GuaranteedMessaging.html[Guaranteed @@ -15,15 +14,14 @@ load balancing * link:jpa.html[JPA] for using a database as a persistence layer, or use any of the many other database component such as link:sql.html[SQL], link:jdbc.html[JDBC], -link:ibatis.html[iBATIS]/link:mybatis.html[MyBatis], +link:mybatis.html[MyBatis], link:hibernate.html[Hibernate] * link:hawtdb.html[HawtDB] for a lightweight key-value persistent store image:http://www.enterpriseintegrationpatterns.com/img/GuaranteedMessagingSolution.gif[image] [[GuaranteedDelivery-Example]] -Example -+++++++ +=== Example The following example demonstrates illustrates the use of http://www.enterpriseintegrationpatterns.com/GuaranteedMessaging.html[Guaranteed @@ -32,33 +30,19 @@ is not considered successfully delivered until the recipient has persisted the message locally guaranteeing its receipt in the event the destination becomes unavailable. -*Using the link:fluent-builders.html[Fluent Builders]* - [source,java] -------------------------- +---- from("direct:start") .to("jms:queue:foo"); -------------------------- - - +---- -**Using the link:spring-xml-extensions.html[Spring XML Extensions]** +And in XML: [source,xml] ------------------------------- +---- <route> <from uri="direct:start"/> <to uri="jms:queue:foo"/> </route> ------------------------------- - -[[GuaranteedDelivery-UsingThisPattern]] -Using This Pattern -++++++++++++++++++ +---- -If you would like to use this EIP Pattern then please read the -link:getting-started.html[Getting Started], you may also find the -link:architecture.html[Architecture] useful particularly the description -of link:endpoint.html[Endpoint] and link:uris.html[URIs]. Then you could -try out some of the link:examples.html[Examples] first before trying -this pattern out.