Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 1. To Create a New Route

Abstract

This tutorial walks you through the process of creating a new Fuse 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 routing project
  • add endpoints to a route
  • connect two endpoints
  • configure the endpoints

Creating the Fuse project

To create a Fuse project:
  1. Open the JBoss perspective.
    This is the default perspective when you start up JBoss Developer Studio for the first time.
  2. On the Toolbar, select FileNewFuse Project to open the New Fuse project wizard, as shown in Figure 1.1, “New Fuse project location page”.

    Figure 1.1. New Fuse project location page

    select workspace
  3. Click Next> to open the New Fuse Project details page, as shown in Figure 1.2, “New Fuse project details page”.

    Figure 1.2. New Fuse project details page

    details of the project
  4. Select camel-archetype-spring.
  5. Enter tutorial in the Group Id: field.
  6. Enter simple-route in the Artifact Id: field.
  7. The Version: field defaults to 1.0.0-SNAPSHOT. To change it, enter a different version identifier.
  8. The Package: field defaults to tutorial.simple.route, the name of the package that contains camel-archetype-spring. To include the route in a different package, enter the name of that package.
  9. Click Finish.
    This procedure creates a Fuse project, simple-route, in Project Explorer that contains everything needed to create and run routes. As shown in Figure 1.3, the files generated for simple-route include:
    • simple-route/pom.xml (Maven project file)
    • simple-route/src/main/resources/META-INF/spring/camel-context.xml (Spring XML file containing the routing rules)

      Figure 1.3. Generated project files

      generated camelContext.xml and pom.xml files

Creating the route

To create the new route:
  1. In Project Explorer, locate simple-route/src/main/resources/META-INF/spring/camel-context.xml.
  2. Right-click it to open the context menu, then select Delete.
    You're going to replace the old camel-context.xml file with your own to create a new route.
  3. In the Delete dialog, click OK to confirm the operation.
  4. In Project Explorer, select simple-route/src/main/resources/META-INF/spring.
  5. Right-click it to open the context menu.
  6. Select NewCamel XML File to open the Camel XML File wizard, as shown in Figure 1.4.

    Figure 1.4. Camel XML File wizard

    New route file wizard
  7. Check that /simple-route/src/main/resources/META-INF/spring appears in the Container: field. Otherwise enter it manually, or select it using the browse button button.
    Note
    The browse button button opens a dialog that displays the folders of all active projects, which you can browse to find and select the files you need.
  8. Check that camelContext.xml appears in the File Name: field. Otherwise enter it manually.
  9. Check that Spring appears in the Framework field, or select it from the field's drop-down list.
  10. Click Finish.
    Note
    By default, Outline view is located in the upper, right corner of the JBoss perspective. To provide more room for Design view to display the graphical representation of your route, drag Outline view to the lower, left corner of the workspace, below Project Explorer.
  11. Click the Source tab at the bottom, left of the canvas to open the new camelContext.xml file in the route editor's Source view, as shown in Figure 1.5, “New camelContext file in the route editor's source view”.

    Figure 1.5. New camelContext file in the route editor's source view

    New Camel route displayed in route editor's source view
  12. Click the Design tab at the bottom, left of the canvas to return to the route editor's Design view.
  13. Drag an Endpoint element ( endpoint icon ) from the Palette to the canvas.
  14. Drag a second Endpoint element from the Palette to the canvas.
  15. Select the first endpoint you dragged onto the canvas.
    The Properties editor, located below the canvas, displays the endpoint's property fields for editing, as shown in Figure 1.6, “Endpoint property editor”.

    Figure 1.6. Endpoint property editor

    endpoint property editor w/ uri field set to file:src/data?noop=true
  16. Enter file:src/data?noop=true in the Uri field. Leave the other fields blank.
  17. Select the second endpoint you dragged onto the canvas.
  18. Enter file:target/messages/others in the Uri field. Leave the other fields blank.
  19. On the canvas, select the first endpoint (file:src/data?noop=true), and drag it's connector arrow ( connector arrow icon ) to the second endpoint (file:target/messages/others), then release it.
    A segmented line connects the two endpoints, as shown in Figure 1.7.

    Figure 1.7. Completed route, diagram view

    connected endpoints displayed in the route editor's Diagram view
    Note
    You can drag the line's bendpoint (orange dot) to change the angle of the line's segments. Doing so creates two new bendpoints, one on either side of the original. This behavior enables you to easily adjust your diagram to accommodate increasingly complex routes.
  20. To quickly align the connected endpoints, right-click the canvas to open the context menu, and then select Layout Diagram.
  21. Select FileSave to save the route.
  22. 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.1.

    Example 1.1. XML for simple route

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:camel="http://camel.apache.org/schema/spring"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://camel.apache.org/schema/spring 
            http://camel.apache.org/schema/spring/camel-spring.xsd">
    
      <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="file:src/data?noop=true"/>
            <to uri="file:target/messages/others"/>
        </route>
    </camelContext>
    
    </beans>

Next steps

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

Further reading

To learn more about: