Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Camel supports three kinds of interceptors:

  • intercept that intercepts each and every processing step while routing an Exchange in the route.
  • interceptFrom that intercepts incoming Exchange in the route.
  • interceptSendToEndpoint that intercepts when an Exchange is about to be sent to the given Endpoint.

These interceptors supports the following features:

  • 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.
  • The intercepted endpoint uri is stored as message header Exchange.INTERCEPTED_ENDPOINT.
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.

...

What happens is that the Exchange is intercepted before each processing step, that means that it will be intercepted before

  • .to("bean:validateOrder")
  • .to("bean:processOrder")

So in this sample we intercept the Exchange twice.

...

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.

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.

...

Info
titleAbout 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.

See Also