...
intercept
that intercepts each and every processing step while routing an Exchange in the route.interceptFrom
that intercepts incoming Exchange in the route.interceptSendToEndpoint
new in Camel 2.0 that intercepts when an Exchange is about to be sent to the given Endpoint.
TODO: Is being reworked in Camel 2.0, so expect some minor changes
These interceptors supports the following features:
- Predicate using
when
to only trigger the interceptor in certain conditions proceed
when used withinterceptFrom
to continue routing from the point of interception when the interceptor is finished.proceed
is default and can be omitted.stop
when used withinterceptFrom
will stops routing the Exchange completely. Camel will by default not stop.skip
when used withinterceptSendToEndpoint
will skip sending the Exchange to the original intended endpoint. Camel will by default not skip.
Intercept
Intercept
is like a regular interceptor that is applied each each processing step the Exchange undergo while its being routed. You can think of it as a AOP before that is applied at each DSL keyword you have defined in your route.
...
.to("bean:validateOrder")
.to("bean:processOrder")
So in this sample we intercept the Exchange twice.TODO: Add support for when predicate
TODO: Add support for stop predicate (proceed is default)
The when
predicate is also support on the intercept
so we can attach a Predicate to only trigger the interception under certain conditions.
For instance in the sample below we only intercept if the message body contains the string word Hello:
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSimpleRouteWhenTest.java} |
Using from Spring DSL
The same hello world sample in Spring DSL would be:
Code Block | ||||
---|---|---|---|---|
| ||||
<camelContext ...> <intercept> <to uri="log:hello"/> </intercept> <route> <from uri="jms:queue:order"/> <to uri="bean:validateOrder"/> <to uri="bean:handleOrder"/> </route> </camelContext> |
And the sample for using the when predicate would be:
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptSimpleRouteWhenTest.xml} |
InterceptFrom
InterceptFrom
is for intercepting any incoming Exchange, in any route (it intercepts all the from
DSLs). This allows you to do some custom behavior for received Exchanges. You can provide a specific uri for a given Endpoint then it only applies for that particular route.
...