Versions Compared

Key

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

...

  • Predicate using when to only trigger the interceptor in certain conditions
  • stop forces to stop continue routing the 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.
  • interceptFrom and interceptSendToEndpoint supports endpoint URI matching by: exact uri, wildcard, regular expression. See advanced section.
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.

...

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 Intercpt

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

  • match by exact URI name. This is the sample we have seen above.
  • match by wildcard
  • match by regular expression.

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.

Code Block
java
java

intercept("jms:*").to("log:fromjms");

Wildcards is match that the text before the * is matched against the given endpoint and if it also starts with the same characters its a match. For instance you can do:

Code Block
java
java

intercept("file://order/inbox/*").to("log:newfileorders");

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:

Code Block
java
java

intercept("jms:queue:(gold|silver)").to("seda:handleFast");
Info
About dynamic and static behavior of interceptFrom and interceptSendToEndpoint
About dynamic and static behavior of interceptFrom and interceptSendToEndpoint

The interceptSendToEndpoint is dynamic hence it will also trigger if a dynamic URI is constructed that Camel was not aware of at startup time.
The interceptFrom is not dynamic as it only intercepts input to routes registered as routes in CamelContext. So if you dynamic construct a Consumer using the Camel API and consumes an Endpoint then the interceptFrom is not triggered.