Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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 with interceptFrom to stop 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 with interceptFrom will stops routing the Exchange completelythe Exchange and mark it as completed successful. Camel will by default not stop.
  • skip when used with interceptSendToEndpoint will skip sending the Exchange to the original intended endpoint. Camel will by default not skip.
Tip
tilestop

stop can be used in general, it does not have to be used with an Intercept you can use it in regular routing as well.

You can also instruct Camel to stop continue routing your message if you set the Exchange.ROUTE_STOP property to "true" or Boolean.TRUE on the Exchange. You can for instance do this from regular Java code in a POJO or Processor.

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: stop is also supported in interceptFrom so you can intercept from certain endpoints and route then elsewhere and stop to not continue routing in the original intended route path.

InterceptSendToEndpoint

Available as of Camel 2.0

...