...
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
tostop
forces to stop 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 completelythe Exchange and mark it as completed successful. 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.
Tip | ||
---|---|---|
| ||
You can also instruct Camel to |
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.
...
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSimpleRouteWhenTest.java} |
And in the route below we want to stop in certain conditions, when the message contains the word 'Hello':
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSimpleRouteWhenStopTest.java} |
Using from Spring DSL
...
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptSimpleRouteWhenTest.xml} |
And the sample for using the when and stop would be:
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptSimpleRouteWhenStopTest.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.
...
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptFromTest.xml} |
Tip |
---|
Notice: |
InterceptSendToEndpoint
Available as of Camel 2.0
...