Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
Chapter 5. To Add Another Route to the CBR Routing Context
Abstract
This tutorial walks you through adding a second route to the
camelContext.xml file in the CBRroute project. The second route:
- takes messages directly from the terminal end of the first route's otherwise branch
- sorts the messages according to customers' country
- sends each message to the corresponding
CBRroute/target/messages/<country>directory
Goals 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
In this tutorial you will:
- reconfigure the existing route for direct connection to a second route
- add a second route to your camelContext
- configure the new route to take messages directly from the otherwise branch of the first route
- add a content-based router to the new route
- add and configure a message header, logging, and target destination to each output branch of the new route's content-based router
Prerequisites 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To complete this tutorial you will need the CBRroute project you modified in Chapter 4, To Add a Content-Based Router.
Note
If you skipped any tutorial after Chapter 2, To Create a New Route, you can use the prefabricated
camelContext5.xml file to work through this tutorial (for details, see Chapter 1, Using the Fuse Tooling Resource Files).
Reconfiguring the existing route for direct connection 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To configure the existing route for direct connection with the new route:
- Open your
CBRroute/src/main/resources/OSGI-INF/blueprint/camelContext.xmlin the route editor. - Click the canvas to display the existing route's properties in the Properties editor.
- Enter
Route1in the Id field. - Select the terminal file: node file:target/messages/toValid to display its properties in the Properties editor.
- In the Uri field, delete the existing text, and then enter
direct:OrderFulfillment. - In the Id field, enter
toFulfill.
Adding the second route 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Note
The route editor displays each route in a multiroute routing context on its own slice of canvas.
To add a route to the routing context:
- Select
. The tooling adds another route to your camelContext, and the route editor opens a clean canvas for you to construct the second route.Outline view, shown here, displays both routes and their components. Clicking on a route in Outline view displays it on the route editor's canvas.Or you can switch between routes by selectingon the menu bar, where RouteName is the string you entered in the route's Id field in the Properties editor. - Click the canvas to display the new route's properties in the Properties editor.
- Enter
Route2in the Id field.
With
Route2 displayed on the route editor's canvas:
- Drag an Generic element (
) from the Palette's Components drawer onto the canvas.
- In the Properties editor, enter
direct:OrderFulfillmentin the Uri field. - Right-click the direct:OrderFulfi... node to open the context menu, and select
. - In the Properties editor, enter
choice2in the Id field. - Right-click the choice2 node to open the context menu, and select
. - In the Properties editor:
- Enter
/order/customer/country = 'USA'in the Expression field. - Select
xpathfrom the Language drop-down menu. - Enter
when/usain the Id field.
- Right-click the when/usa node to open the context menu, and select
. - In the Properties editor:
- Enter
Destinationin the Header Name field. - Enter
USAin the Expression field. - Select from the drop-down menu.
- Enter
setHead_usain the Id field,
- Right-click the setHead_usa node to open the context menu, and select
. - In the Properties editor:
- Enter
Valid order - ship animals to USA customerin the Message field. - Enter
log_usain the Id field.
- Right-click the log_usa node to open the context menu, and select
. - In the Properties editor:
- Replace directoryName with
target/messages/USAin the Uri field. - Enter
toUSin the Id field.
The USA branch of Route2 should look like this:
With
Route2 displayed on the canvas:
- Right-click the choice2 node again to open the context menu, and select
. - In the Properties editor:
- Enter
/order/customer/country = 'Great Britain'in the Expression field. - Select
xpathfrom the Language drop-down menu. - Enter
when/gbin the Id field.
- Right-click the when/gb node to open the context menu, and select
. - In the Properties editor:
- Enter
Destinationin the Header Name field. - Enter
UKin the Expression field. - Select from the drop-down menu.
- Enter
setHead_ukin the Id field,
- Right-click the setHead_uk node to open the context menu, and select
. - In the Properties editor:
- Enter
Valid order - ship animals to UK customerin the Message field. - Enter
log_ukin the Id field.
- Right-click the log_uk node to open the context menu, and select
. - In the Properties editor:
- Replace directoryName with
target/messages/GreatBritainin the Uri field. - Enter
toUKin the Id field.
The Great Britain branch of Route2 should look like this:
With
Route2 displayed on the canvas:
- Right-click the choice2 node again to open the context menu, and select
. - In the Properties editor:
- Enter
/order/customer/country = 'Germany'in the Expression field. - Select
xpathfrom the Language drop-down menu. - Enter
when/gerin the Id field.
- Right-click the when/ger node to open the context menu, and select
. - In the Properties editor:
- Enter
Destinationin the Header Name field. - Enter
Germanyin the Expression field. - Select from the drop-down menu.
- Enter
setHead_gerin the Id field,
- Right-click the setHead_ger node to open the context menu, and select
. - In the Properties editor:
- Enter
Valid order - ship animals to Germany customerin the Message field. - Enter
log_gerin the Id field.
- Right-click the log_ger node to open the context menu, and select
. - In the Properties editor:
- Replace directoryName with
target/messages/Germanyin the Uri field. - Enter
toGRin the Id field.
The Germany branch of Route2 should look like this:
With
Route2 displayed on the canvas:
- Right-click the choice2 node again to open the context menu, and select
. - In the Properties editor:Enter
else/frin the Id field. - Right-click the else/fr node to open the context menu, and select
. - In the Properties editor:
- Enter
Destinationin the Header Name field. - Enter
Francein the Expression field. - Select from the drop-down menu.
- Enter
setHead_frin the Id field,
- Right-click the setHead_fr node to open the context menu, and select
. - In the Properties editor:
- Enter
Valid order - ship animals to France customerin the Message field. - Enter
log_frin the Id field.
- Right-click the log_fr node to open the context menu, and select
. - In the Properties editor:
- Replace directoryName with
target/messages/Francein the Uri field. - Enter
toFRin the Id field.
The France branch of Route2 should look like this:
Saving the new routing context 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
- On the toolbar, select
to save the routing context. The routes on the canvas should look like this:Figure 5.1. Completed route1
Figure 5.2. Completed route2
- Click the Source tab at the bottom, left of the canvas to display the XML for the route.The
camelContextelement should look like that shown in Example 5.1.Example 5.1. XML for dual-route content-based router
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can run the new route as described in the section called “Running the route”.
Check the end of the Console's output. You should see these lines:
Check the target destinations in Project Explorer to verify that the routes executed properly:
- Select
CBRroute. - Right-click it to open the context menu, then select .
- Expand the folder
target/messages/as shown in Figure 5.3. Themessage*.xmlfiles should be dispersed in your target destinations like this:Figure 5.3. Target message destinations in Project Explorer
NoteTo view message content, double-click a message to open it in the route editor's xml editor.
Further reading 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To learn more about the direct component see the Red Hat JBoss Fuse: Apache Camel Component Reference at Red Hat JBoss Fuse 6.x documentation