...
Tip | ||
---|---|---|
| ||
You can also instruct Camel to |
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} |
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: |
Anchor | ||||
---|---|---|---|---|
|
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} |
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpointWhen.xml} |
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:
...