...
Camel supports two kinds of interceptors
intercept
that intercepts incoming ExchangeinterceptEndpoint
new in Camel 2.0 that intercepts when an Exchange is about to be sent to the given Endpoint.
Both of these interceptors supports
- Predicat using
when
to only trigger the interceptor in certain conditions proceed
to continue routing from the point of interception when the interceptor is finished.proceed
is default and can be omitted.stop
when used withintercept
will stops routing the Exchange completely. Camel will by default not stop.stop
when used withinterceptEndpoint
will skip sending the Exchange to the original intended endpoint. Camel will by default not skip.
Intercept
...
Intercept is for intercepting any incoming Exchange, that is it intercepts the from
DSL. This allows you to do some custom behavior for received Exchanges.
So lets Lets start with the logging example. We want to log all the incoming requests so we use intercept
to route to the Log component. As proceed
is default then the Exchange will continue its route, and thus it will continue to mock:first
.
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleLogTest.java} |
You can also attach a Predicate to only trigger if certain conditions is meet. For instance in the route below we intercept when a test message is send to us, so we can do some custom processing before we continue routing:
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java} |
And if we want to filter out certain messages we can use the stop()
to instruct Camel to stop continue routing the Exchange:
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java} |
TODO: advanced with proceed, stop in a choice etc.
InterceptEndpoint
Available as of Camel 2.0
...