Search

Chapter 2. Migrating Camel Routes from Fuse 7 to Camel Extensions for Quarkus (CEQ)

download PDF
Note

You can define Camel routes in CEQ applications using Java DSL, XML IO DSL, or YAML.

2.1. Java DSL route migration example

To migrate a Java DSL route definition from your Fuse application to CEQ, you can copy your existing route definition directly to your CEQ application and add the necessary dependencies to your CEQ pom.xml file.

In this example, we will migrate a content-based route definition from a Fuse 7 application to a new CEQ application by copying the Java DSL route to a file named Routes.java in your CEQ application.

Procedure

  1. Using the code.quarkus.redhat.com website, select the extensions required for this example:

    • camel-quarkus-file
    • camel-quarkus-xpath
  2. Navigate to the directory where you extracted the generated project files from the previous step:

    $ cd <directory_name>
  3. Create a file named Routes.java in the src/main/java/org/acme/ subfolder.
  4. Add the route definition from your Fuse application to the Routes.java, similar to the following example:

    package org.acme;
    
    import org.apache.camel.builder.RouteBuilder;
    
    public class Routes extends RouteBuilder {
    	// Add your Java DSL route definition here
        public void configure() {
    	    from("file:work/cbr/input")
                .log("Receiving order ${file:name}")
                .choice()
                    .when().xpath("//order/customer/country[text() = 'UK']")
                        .log("Sending order ${file:name} to the UK")
                        .to("file:work/cbr/output/uk")
                    .when().xpath("//order/customer/country[text() = 'US']")
                        .log("Sending order ${file:name} to the US")
                        .to("file:work/cbr/output/uk")
                    .otherwise()
                        .log("Sending order ${file:name} to another country")
                        .to("file:work/cbr/output/others");
        }
    
    }
  5. Compile your CEQ application.

    mvn clean compile quarkus:dev
Note

This command compiles the project, starts your application, and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application.

2.2. Blueprint XML DSL route migration

To migrate a Blueprint XML route definition from your Fuse application to CEQ, use the camel-quarkus-xml-io-dsl extension and copy your Fuse application route definition directly to your CEQ application. You will then need to add the necessary dependencies to the CEQ pom.xml file and update your CEQ configuration in the application.properties file.

Note

CEQ supports Camel 3, whereas Fuse 7 supports Camel 2. For more information relating to upgrading Camel when you migrate your Red Hat Fuse 7 application to CEQ, see Migrating from Camel 2 to Camel 3.

For more information about using beans in Camel Quarkus, see the CDI and the Camel Bean Component section in the Developing Applications with Camel Extensions for Quarkus guide.

2.2.1. XML-IO-DSL limitations

You can use the camel-quarkus-xml-io-dsl extension to assist with migrating a Blueprint XML route definition to CEQ.

The camel-quarkus-xml-io-dsl extension only supports the following <camelContext> sub-elements:

  • routeTemplates
  • templatedRoutes
  • rests
  • routes
  • routeConfigurations
Note

As Blueprint XML supports other bean definitions that are not supported by the camel-quarkus-xml-io-dsl extension, you may need to rewrite other bean definitions that are included in your Blueprint XML route definition.

You must define every element (XML IO DSL) in a separate file. For example, this is a simplified example of a Blueprint XML route definition:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <restConfiguration contextPath="/camel" />
        <rest path="/books">
            <get uri="/">
                <to ..../>
            </get>
        </rest>
        <route>
            <from ..../>
        </route>
    </camelContext>
</blueprint>

You can migrate this Blueprint XML route definition to CEQ using XML IO DSL as defined in the following files:

src/main/resources/routes/camel-rests.xml

<rests xmlns="http://camel.apache.org/schema/spring">
    <rest path="/books">
    <get path="/">
        <to ..../>
    </get>
    </rest>
</rests>

src/main/resources/routes/camel-routes.xml

<routes xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from ..../>
    </route>
</routes>

You must use Java DSL to define other elements which are not supported, such as <restConfiguration>. For example, using a route builder defined in a camel-rests.xml file as follows:

src/main/resources/routes/camel-rests.xml

import org.apache.camel.builder.RouteBuilder;
public class Routes extends RouteBuilder {
    public void configure() {
       restConfiguration()
            .contextPath("/camel");
    }
}

2.2.2. Blueprint XML DSL route migration example

Note

For more information about using the XML IO DSL extension, see the XML IO DSL documentation in the Camel Extensions for Quarkus Reference.

In this example, you are migrating a content-based route definition from a Fuse application to a new CEQ application by copying the Blueprint XML route definition to a file named camel-routes.xml in your CEQ application.

Procedure

  1. Using the code.quarkus.redhat.com website, select the following extensions for this example:

    • camel-quarkus-xml-io-dsl
    • camel-quarkus-file
    • camel-quarkus-xpath
  2. Select Generate your application to confirm your choices and display the overlay screen with the download link for the archive that contains your generated project.
  3. Select Download the ZIP to save the archive with the generated project files to your machine.
  4. Extract the contents of the archive.
  5. Navigate to the directory where you extracted the generated project files from the previous step:

    $ cd <directory_name>
  6. Create a file named camel-routes.xml in the src/main/resources/routes/ directory.
  7. Copy the <route> element and sub-elements from the following blueprint-example.xml example to the camel-routes.xml file:

    blueprint-example.xml

    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
        <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint">
            <route id="cbr-route">
                <from id="_from1" uri="file:work/cbr/input"/>
                <log id="_log1" message="Receiving order ${file:name}"/>
                <choice id="_choice1">
                    <when id="_when1">
                        <xpath id="_xpath1">/order/customer/country = 'UK'</xpath>
                        <log id="_log2" message="Sending order ${file:name} to the UK"/>
                        <to id="_to1" uri="file:work/cbr/output/uk"/>
                    </when>
                    <when id="_when2">
                        <xpath id="_xpath2">/order/customer/country = 'US'</xpath>
                        <log id="_log3" message="Sending order ${file:name} to the US"/>
                        <to id="_to2" uri="file:work/cbr/output/us"/>
                    </when>
                    <otherwise id="_otherwise1">
                        <log id="_log4" message="Sending order ${file:name} to another country"/>
                        <to id="_to3" uri="file:work/cbr/output/others"/>
                    </otherwise>
                </choice>
                <log id="_log5" message="Done processing ${file:name}"/>
            </route>
        </camelContext>
    </blueprint>

    camel-routes.xml

    <route id="cbr-route">
        <from id="_from1" uri="file:work/cbr/input"/>
        <log id="_log1" message="Receiving order ${file:name}"/>
        <choice id="_choice1">
            <when id="_when1">
                <xpath id="_xpath1">/order/customer/country = 'UK'</xpath>
                <log id="_log2" message="Sending order ${file:name} to the UK"/>
                <to id="_to1" uri="file:work/cbr/output/uk"/>
            </when>
            <when id="_when2">
                <xpath id="_xpath2">/order/customer/country = 'US'</xpath>
                <log id="_log3" message="Sending order ${file:name} to the US"/>
                <to id="_to2" uri="file:work/cbr/output/us"/>
            </when>
            <otherwise id="_otherwise1">
                <log id="_log4" message="Sending order ${file:name} to another country"/>
                <to id="_to3" uri="file:work/cbr/output/others"/>
            </otherwise>
        </choice>
        <log id="_log5" message="Done processing ${file:name}"/>
    </route>

  8. Modify application.properties

    # Camel
    #
    camel.context.name = camel-quarkus-xml-io-dsl-example
    camel.main.routes-include-pattern = file:src/main/resources/routes/camel-routes.xml
  9. Compile your CEQ application.

    mvn clean compile quarkus:dev
    Note

    This command compiles the project, starts your application, and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application.

2.3. Additional resources

For more information about Camel Extensions for Quarkus (CEQ), see the following documentation:

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.