Versions Compared

Key

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

...

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 on 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.

The classic Hello World example would beis:

Code Block
intercept()
  .to("log:hello");

from("jms:queue:order")
  .to("bean:validateOrder")
  .to("bean:processOrder");

...

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}
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.

...

Intercept is of course also available using Spring DSL as shown in the sample below:

Wiki Markup
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptFromTest.xml}

Tip

NoticeNote: stop() is also supported in interceptFrom() so you can intercept from certain endpoints and route then elsewhere and and stop() to not continue routing in the original intended route path.

Anchor
InterceptSendToEndpoint
InterceptSendToEndpoint

InterceptSendToEndpoint

Available as of Camel 2.0

...

Intercept endpoint is of course also available using Spring DSL. We start with the first example from above in Spring DSL:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpoint.xml}
And the second. Notice how we can leverage the Simple language for the Predicate:
Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpointWhen.xml}
And the third with the skip; notice skip is set with the skipSendToOriginalEndpoint attribute on the interceptSendToEndpoint tag:
Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpointSkip.xml}

Advanced usage

...

of Intercept

The interceptFrom and interceptSendToEndpoint supports endpoint URI matching by the following rules in the given order:

...

The real endpoint that was intercepted is stored as URI in the message IN header with the key Exchange.INTERCEPTED_ENDPOINT. This allows you to get hold of this information, when you for instance match by wildcard. Then you know the real endpoint that was intercepted and can react accordingly.

Match by

...

Wildcard

Match by wildcard allows you to match a range of endpoint or all of a given type. For instance use uri="file:*" will match all File based endpoints:

...

To intercept any files received from the order/inbox folder.

Match by

...

Regular Expression

Match by regular expression is just like match by wildcard but using regex instead. So if we want to intercept incoming messages from gold and silver JMS queues we can do:

...