To Create a New Route

This tutorial walks you through the process of creating a new Fuse Integration project, adding a route to it, and adding two endpoints to the route. It assumes that you have already set up your workspace and that Red Hat JBoss Fuse Tooling is running inside Red Hat JBoss Developer Studio.

Goals

In this tutorial you will:

  • create a Fuse Integration project

  • create a new routing context

  • create a route

    • add file endpoints to the route

    • connect the endpoints

    • configure the endpoints

  • create a folder in your project to store test messages that you create for your route

  • create the test messages

Prerequisites

  • JBoss Developer Studio 9.1.0 installed

  • Red Hat JBoss Fuse Tooling 8.0.0 installed in JBoss Developer Studio 9.1.0

  • The JBoss Developer Studio > Preferences > Fuse Tooling > editor > If enabled the ID values will be used for labels if existing option is set. Otherwise the labeling on the patterns and components placed on the canvas will differ from that shown in these tutorials.

When you start up JBoss Developer Studio for the first time, it opens in JBoss perspective:

JBoss View on JBDS startup
[Note]Note

You can start this tutorial in JBoss perspective or in Fuse Integration perspective. If you start it in JBoss perspective, the tooling will ask to switch you to Fuse Integration perspective at the appropriate point in the tutorial.

Creating the Fuse Integration project

To create a Fuse Integration project:

  1. On the menu bar, select File > New > Other > JBoss Fuse > Fuse Integration Project to open the New Fuse Integration Project wizard:

  2. Enter CBRroute in the Project Name field.

  3. Leave the Use default workspace location option as is.

  4. Click Next to open the Select a Target Runtime page:

  5. Accept No Runtime selected for Target Runtime and 2.17.0.redhat-630175 for Camel Version.

    [Note]Note

    You will add the runtime later in the tutorial To Publish a Fuse Project to Red Hat JBoss Fuse.

  6. Click Next to open the Advanced Project Setup page:

  7. Leave the Start with an empty project and Blueprint DSL options selected.

  8. Click Finish.

    Fuse Tooling starts downloading from the Maven repository all of the files it needs to build the project, and then adds the new project to Project Explorer.

    If you are not in Fuse Integration perspective, the tooling asks whether you want to switch to it now:

  9. Click Yes to open the new CBRroute project in Fuse Integration perspective:

    The new CBRroute project contains everything needed to create and run routes. As shown in Figure 1, the files generated for CBRroute include:

    • CBRroute/pom.xml (Maven project file)

    • CBRroute/src/main/resources/OSGI-INF/blueprint/blueprint.xml (Blueprint XML file containing the routing rules)

      Figure 1. Generated project files

      generated blueprint.xml and pom.xml files

  10. In Project Explorer, double-click the pom.xml entry to open the file in the tooling's XML editor.

  11. In the pom.xml file, modify the lines outlined in red, as shown:

    • Change the value of the groupId element to tutorial.

    • Change the value of the artifactId element to cbr-route.

      [Note]Note

      The tooling combines the groupId string with the artifactId string to generate the symbolic name of the CBRroute project's bundle (in this case, tutorial.cbr-route), which you will later publish to a JBoss Fuse 6.3 server runtime in To Publish a Fuse Project to Red Hat JBoss Fuse.

    • Delete the <camel.version> element. It is not used.

    • Change the value of the <jboss.fuse.bom.version> to 6.3.0.redhat-XXX, where XXX is the build number of the installed JBoss Fuse runtime (and is included in the install directory's name).

    • Delete the <version> element from each <dependency>: camel-core, camel-blueprint, and camel-test-blueprint:

      As versions are defined in the JBoss Fuse parent bom, these steps will resolve any harmless Overriding managed version 2.17.0.redhat-630xxx for camel- ... warnings the Problems pane may display.

  12. Select File > Save to save the changes you made to the pom.xml file.

  13. In Project Explorer, right-click CBRroute to open the context menu.

  14. Select Maven > Update Project to open the Update Maven Project wizard:

  15. In the Available Maven Codebases pane, select CBRroute, and then check the option Force Updates of Snapshots/Releases to enable it. Leave all other options as is.

  16. Click OK.

    The Maven CBRroute codebase is now synchronized with the project's newly modified pom.xml file.

Creating the route

To create the route:

  1. Click the Design tab at the bottom, left of the canvas to return to the route editor's Design view.

  2. Drag a File component (File icon) from the Palette's Components drawer to the canvas, and drop it in the Route_route1 container node.

    The File component changes to a From _from1 node inside the Route_route1 container node.

  3. On the canvas, select the From _from1 node.

    The Properties editor, located below the canvas, displays the node's property fields for editing.

  4. In the Properties editor, select the Advanced tab:

    You need to create a folder for the project's source data and enter that folder's name in the Directory Name field.

    1. In Project Explorer, right-click CBRroute/src/ to open the context menu.

    2. Select New > Folder to open the New Folder wizard:

    3. Check that CBRroute/src appears in the Enter or select the parent folder field. Otherwise enter it manually, or select it from the graphical representation of the project's hierarchy.

    4. In the Folder name field, enter data, and then click Finish.

      The new data folder appears in Project Explorer, under the src folder:

  5. Return to the Advanced tab, in the Properties editor.

  6. In the Directory Name field, enter src/data:

    The path src/data is relative to the project's directory.

  7. On the Consumer tab, enable the Noop option by clicking its check box.

    The Noop option prevents the message#.xml files being deleted from the src/data folder, and it enables idempotency to ensure that each message#.xml file is consumed only once.

  8. Select the Details tab to open the file node's Details page.

    The tooling automatically populates the Uri field with the Directory Name and Noop properties you configured on the Advanced tab. It also populates the Id field with an autogenerated ID (_from1):

  9. Leave the autogenerated Id as is.

  10. Drag another File component from the Palette's Components drawer and drop it in the Route_route1 container node.

    The File component changes to a To _to1 node inside the Route_route1 container node.

  11. On the canvas, select the To _to1 node.

    The Properties editor, located below the canvas, displays the node's property fields for editing.

  12. On the Details tab, enter file:target/messages/others in the Uri field, and _Others in the Id field:

    [Note]Note

    The tooling will create the target/messages/others folder at runtime.

  13. In the Route_route1 container, select the From _from1 node and drag it's connector arrow (connector arrow icon) over the To_Others node, then release it:

    [Note]Note

    The two file nodes are connected and aligned on the canvas according to the route editor's layout direction preference setting. The choices are Right and Down (default).

    [Note]Note

    If you do not connect the nodes before you close the project, the tooling automatically connects them when you reopen it.

  14. Select File > Save to save the route.

  15. Click the Source tab at bottom, left of the canvas.

    Source view displays the XML for the route. The camelContext element will look like Example 1:

    Example 1. XML for CBRroute

    <?xml version="1.0" encoding="UTF-8"?>
    
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0      
        https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd                                 
        http://camel.apache.org/schema/blueprint      
        http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    
        <camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
            <route id="_route1">
                <from id="_from1" uri="file:src/data?noop=true"/>
                <to id="_Others" uri="file:target/messages/others"/>
            </route>
        </camelContext>
    </blueprint>

Creating test messages

Before you can run your route, you need to create test messages to send through it.

  1. In Project Explorer, right-click CBRroute to open the context menu.

  2. Click New > Fuse Message to open the Fuse Message File wizard:

  3. Check that CBRroute/src/data appears in the Enter or select the parent folder field. Otherwise enter it manually, or select it from the graphical representation of the project's hierarchy.

  4. In File Name:, enter message1.xml.

  5. Click Finish to open the test message, message1.xml, in Design View:

  6. Click the Source tab at the bottom, right of the canvas to switch to Source view:

  7. In Source view, enter this text:

    <?xml version="1.0" encoding="UTF-8"?>
                            
    <order>
      <customer>
        <name>Brooklyn Zoo</name>
        <city>Brooklyn</city>
        <country>USA</country>
      </customer>
      <orderline>
        <animal>wombat</animal>
        <quantity>15</quantity>
        <maxAllowed>25</maxAllowed>
      </orderline>
    </order>
    [Note]Note

    You can safely ignore the Warning icon on line 1 of the newly created message1.xml file, which advises you that there are no grammar constraints (DTD or XML Schema) referenced by the document.

  8. Save the file, and close it.

  9. If you haven't already done so, download the prefabricated test message files (see Using the Fuse Tooling Resource Files for instructions). Copy message2.xml through message6.xml into the newly created CBRroute/src/data folder. You will use all six test messages in the remaining Fuse Tooling tutorials.

    Table 1 shows the contents of each remaining prefabricated message file.

    Table 1. Preconstructed test messages

    msg#<name><city><country><animal><quantity><maxAllowed>
    2San Diego ZooSan DiegoUSAgiraffe32
    3London ZooLondonGreat Britainpenguin1220
    4Bristol ZooBristolGreat Britainemu54
    5Paris ZooParisFrancegiraffe22
    6Hellabrunn GardensMunichGermanypenguin1820

Next steps

After you have created and designed your route, you can run it by deploying it into your local Apache Camel runtime, as described in To Run a Route.

Further reading

To learn more about: