
Component |
Exception |
|
Function |
cIntercept intercepts the messages in all the sub-routes on a |
|
Purpose |
cIntercept intercepts each message sub-route and redirects it |
|
Usage |
cIntercept is a start component of a sub-route. |
|
Connections |
Row / Route |
Select the Route link to intercept all the messages of all |
|
Trigger / When |
Select the When In the In the All |
Limitation |
To keep the original sub-routes untouched, cIntercept only be used in a separate sub-route |
In this scenario, messages on two sub-routes are intercepted and routed along a new
sub-route, which is then terminated before the original sub-routes continue.

This scenario requires five cFile components, one
cIntercept component, one cProcessor component, and one cStop
component.
-
From the Messaging folder of the
Palette, drop four cFile components onto the design workspace. -
Connect the two pairs of cFile components
using Row > Route connections. Messages on these two sub-routes will be
intercepted. -
From the Exception folder, drop a cIntercept component onto the design workspace.
-
From the Processor folder, drop a
cProcessor component onto the design
workspace. -
From the Messaging folder, drop a fifth
cFile component onto the design
workspace. -
From the Miscellaneous folder, drop a
cStop component onto the design
workspace. -
Connect these four components one to the next using Row > Route connections.
Along this sub-route, intercepted messages will be directed to a new
endpoint before the entire Route is terminated. -
Label the components to better identify their roles in the Route.
In this scenario, the cIntercept component intercepts all
the messages on all the sub-routes as soon as the messages are sent and does not
have properties to set. The cStop component stops
the sub-route on which it is dropped before it completes and does not have
properties to set. Therefore, you only need to configure the messaging endpoints and
monitor components.
-
Double-click the cFile component labeled
Sender_1 to display its Basic settings view in the Component tab. -
In the Path field, specify the file path
to the first source your are going to send messages from, and leave the
other parameters as they are. -
Double-click the cFile component labeled
Receiver_1 to display its Basic settings view in the Component tab. -
In the Path field, specify the file path
to the first destination you are going to send messages to, and leave the
other parameters as they are. -
In the same way, set the cFile components
labeled Sender_2 and Receiver_2 across the second sub-route. -
Double-click the cProcessor component,
which is labeled Monitor, to display its
Basic settings view in the Component tab, and customize the code in the
Code area to display the file names of
the messages intercepted on the console:12System.out.println("Message intercepted: "+exchange.getIn().getHeader("CamelFileName")); -
Double-click the cFile component labeled
Receiver_3 to display its Basic settings view in the Component tab. -
In the Path field, specify the file path
to the destination for the intercepted messages, and leave the other
parameters as they are. -
Press Ctrl+S to save your Route.
-
Click the Code tab at the bottom of the
design workspace to have a look at the generated code.As shown in this piece of code, Interceptor intercepts
all messages on route, the intercepted messages are directed
.to
the endpoint Receiver_3, and cStop_1
terminates message routing before the messages are routedfrom
the endpoint Sender_1
.to
the endpoint Receiver_1
andfrom
the endpoint Sender_2
.to
the endpoint Receiver_2. -
Click the Run view and click the
Run button to launch the execution of
your Route. You can also press F6 to
execute it.RESULT: Files are sent from the endpoints, caught by the cIntercept component, monitored by the cProcessor component and sent to a new endpoint, and then
the original sub-routes are terminated before they can continue.