Chapter 4. Getting Started with Red Hat build of Apache Camel for Quarkus


This guide introduces Red Hat build of Apache Camel for Quarkus, the various ways to create a project and how to get started building an application using Red Hat build of Apache Camel for Quarkus:

Red Hat build of Apache Camel for Quarkus brings the integration capabilities of Apache Camel and its vast component library to the Quarkus runtime.

The benefits of using Red Hat build of Apache Camel for Quarkus include the following:

  • Enables users to take advantage of the performance benefits, developer joy and the container first ethos which Quarkus provides.
  • Provides Quarkus extensions for many of the Apache Camel components.
  • Takes advantage of the many performance improvements made in Camel, which results in a lower memory footprint, less reliance on reflection and faster startup times.

4.2.1. Overview

You can use code.camel.redhat.com to generate a Quarkus Maven project which automatically adds and configures the extensions that you want to use in your application.

This section walks you through the process of creating a Quarkus Maven project with Red Hat build of Apache Camel for Quarkus including:

  • Creating the skeleton application using code.camel.redhat.com
  • Adding a simple Camel route
  • Exploring the application code
  • Compiling the application in development mode
  • Testing the application

You can bootstrap and generate projects on code.camel.redhat.com.

The Red Hat build of Apache Camel for Quarkus extensions are located under the 'Integration' heading.

If you need additional extensions, use the 'search' field to find them.

Select the component extensions that you want to work with and click 'Generate your application' to download a basic skeleton project.

You can also push the project directly to GitHub.

For more information about using code.camel.redhat.com to generate Quarkus Maven projects, see Creating a Quarkus Maven project in the Getting started with Red Hat build of Quarkus guide.

Procedure

  1. In the code.camel.redhat.com website, select the following extensions:

    • camel-quarkus-rest
    • camel-quarkus-jackson
    • camel-quarkus-direct

      Note

      Do not compile the application on code.quarkus.redhat.com (in the final step of the procedure). Instead, use the compile command described in the Section 4.2.5, “Development mode” section below.

  2. Navigate to the directory where you extracted the generated project files from the previous step:

    cd <directory_name>

4.2.3. Explore the application code

The application has two compile dependencies which are managed within the com.redhat.quarkus.platform:quarkus-camel-bom that is imported in <dependencyManagement>.:

pom.xml

<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>com.redhat.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>
    <!-- The latest 3.27.x version from https://maven.repository.redhat.com/ga/com/redhat/quarkus/platform/quarkus-bom -->
</quarkus.platform.version>

...

<dependency>
    <groupId>${quarkus.platform.group-id}</groupId>
    <artifactId>${quarkus.platform.artifact-id}</artifactId>
    <version>${quarkus.platform.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
<dependency>
    <groupId>${quarkus.platform.group-id}</groupId>
    <artifactId>quarkus-camel-bom</artifactId>
    <version>${quarkus.platform.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

Note

For more information about BOM dependency management, see Developing Applications with Red Hat build of Apache Camel for Quarkus

The application is configured by properties defined within src/main/resources/application.properties, for example, the camel.context.name can be set there.

4.2.4. Adding a simple Camel route

Note

In this example, we use the simple example from the camel-quarkus-examples repository. It consists of the two simple classes Fruit.java, Legume.java and the route definitions Routes.java .

Procedure

  1. Create a file named Fruit.java in the src/main/java/org/acme/ subfolder.
  2. Add the class as shown in the following code snippet:

    Fruit.java

    package org.acme.rest.json;
    
    import java.util.Objects;
    
    import io.quarkus.runtime.annotations.RegisterForReflection;
    
    /**
     * A REST entity representing a fruit.
     */
    @RegisterForReflection // Lets Quarkus register this class for reflection during the native build
    public class Fruit {
        private String name;
        private String description;
    
        public Fruit() {
        }
    
        public Fruit(String name, String description) {
            this.name = name;
            this.description = description;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (!(obj instanceof Fruit)) {
                return false;
            }
    
            Fruit other = (Fruit) obj;
    
            return Objects.equals(other.name, this.name);
        }
    
        @Override
        public int hashCode() {
            return Objects.hash(this.name);
        }
    }

  3. Create a file named Legume.java in the src/main/java/org/acme/ subfolder.
  4. Add the class as shown in the following code snippet:

    Legume.java

    package org.acme.rest.json;
    
    import java.util.Objects;
    
    import io.quarkus.runtime.annotations.RegisterForReflection;
    
    /**
     * A REST entity representing a legume.
     */
    @RegisterForReflection // Lets Quarkus register this class for reflection during the native build
    public class Legume {
        private String name;
        private String description;
    
        public Legume() {
        }
    
        public Legume(String name, String description) {
            this.name = name;
            this.description = description;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (!(obj instanceof Legume)) {
                return false;
            }
    
            Legume other = (Legume) obj;
    
            return Objects.equals(other.name, this.name);
        }
    
        @Override
        public int hashCode() {
            return Objects.hash(this.name);
        }
    }

  5. Create a file named Routes.java in the src/main/java/org/acme/ subfolder.
  6. Add a Camel Rest route as shown in the following code snippet:

    Routes.java

    package org.acme.rest.json;
    
    import java.util.Collections;
    import java.util.LinkedHashSet;
    import java.util.Set;
    
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.model.rest.RestBindingMode;
    
    /**
     * Camel route definitions.
     */
    public class Routes extends RouteBuilder {
        private final Set<Fruit> fruits = Collections.synchronizedSet(new LinkedHashSet<>());
        private final Set<Legume> legumes = Collections.synchronizedSet(new LinkedHashSet<>());
    
        public Routes() {
    
            /* Let's add some initial fruits */
            this.fruits.add(new Fruit("Apple", "Winter fruit"));
            this.fruits.add(new Fruit("Pineapple", "Tropical fruit"));
    
            /* Let's add some initial legumes */
            this.legumes.add(new Legume("Carrot", "Root vegetable, usually orange"));
            this.legumes.add(new Legume("Zucchini", "Summer squash"));
        }
    
        @Override
        public void configure() throws Exception {
    
            restConfiguration().bindingMode(RestBindingMode.json);
    
            rest("/fruits")
                    .get()
                    .to("direct:getFruits")
    
                    .post()
                    .type(Fruit.class)
                    .to("direct:addFruit");
    
            rest("/legumes")
                    .get()
                    .to("direct:getLegumes");
    
            from("direct:getFruits")
                    .setBody().constant(fruits);
    
            from("direct:addFruit")
                    .process().body(Fruit.class, fruits::add)
                    .setBody().constant(fruits);
    
            from("direct:getLegumes")
                    .setBody().constant(legumes);
        }
    }

    For more information about this example, see camel-quarkus-examples repository.

4.2.5. Development mode

mvn clean compile quarkus:dev

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

You can check the application in your browser. (For example, for the rest-json sample application, access http://localhost:8080/fruits)

If you change the application code, for example, change 'Apple' to 'Orange', your application automatically updates. To see the changes applied, refresh your browser.

Refer to Quarkus documentation Development mode section for more details about the development mode.

4.2.6. Packaging and running the application

4.2.6.1. JVM mode

Procedure

  1. Run mvn package to prepare a thin jar for running on a stock JVM:

    mvn clean package
    $ ls -lh target/quarkus-app
    ...
    -rw-r--r--. 1 user user 238K Oct 11 18:55  quarkus-run.jar
    ...
    Note

    The thin jar contains just the application code. You also need the dependencies in target/quarkus-app/lib to run it.

  2. Run the jar as follows:

    java -jar target/quarkus-app/quarkus-run.jar
    ...
    [io.quarkus] (main) Quarkus started in 1.163s. Listening on: http://[::]:8080
Note

The boot time should be around a second.

4.2.6.2. Native mode

Procedure

To prepare a native executable, do as follows:

  1. Run the command mvn clean package -Pnative:

    mvn clean package -Pnative
    $ ls -lh target
    ...
    -rwxr-xr-x. 1 user user  46M Oct 11 18:57  code-with-quarkus-1.0.0-SNAPSHOT-runner
    ...
    Note

    The runner has no .jar extension and has the x (executable) permission set. You can run it directly:

    ./target/*-runner
    ...
    [io.quarkus] (main) Quarkus started in 0.013s. Listening on: http://[::]:8080
    ...

    The application started in 13 milliseconds.

  2. View the memory usage with the ps -o rss,command -p $(pgrep code-with) command :

    ps -o rss,command -p $(pgrep code-with)
      RSS COMMAND
    65852 ./target/code-with-quarkus-1.0.0-SNAPSHOT-runner

    The application uses 65 MB of memory.

Tip

See Producing a native executable in the Compiling your Quarkus applications to native executables guide for additional information about preparing a native executable.

Tip

4.3. Building your first project with Kaoto

You can create Camel projects with Kaoto (Kamel Orchestration Tool), a low to no code integration designer for integrations based on Apache Camel.

4.3.1. Getting started with Kaoto

Note

This section assumes you have already installed VS Code with the Kaoto extension. For details, see the Kaoto documentation.

You also need to have Camel CLI installed. For details, see the Using Camel CLI with Red Hat build of Apache Camel for Quarkus.

This section walks you through the process of creating a Camelproject with Kaoto in VS Code:

  • Set up a workspace in VS Code
  • Create your integration
  • Create your first Camel Route
  • Run your Camel Route locally
  • View the source code for the Camel Route

4.3.1.1. Preparing the Workspace

To create a Visual Studio Code workspace for your project:

  1. Open your Visual Studio Code instance.
  2. Select the Kaoto view by clicking the Kaoto VS Code Kaoto Camel button on the left hand side.

    empty vscode
  3. Select a workspace folder to store our project files:

    1. Click the Open Folder button or open the File menu and choose Open Folder.

      open folder
  4. Browse to a suitable folder and click Open.

The folder is added to the File Explorer window on the left hand side.

4.3.1.2. Creating your first Camel Route

In the Kaoto view, you can create a Camel Route.

  1. Expand the Integration section.
  2. Click the New file…​ button on the right and side of the Integration section header
  3. Select New Camel Route.
  4. Choose format for the Route definition file (XML or YAML).
  5. Click Select to choose folder to store the file in.
  6. Enter a name for the file (without file extension).

    A basic route is created and displayed in the editor window:

    new route
4.3.1.2.1. Launching the Camel Route

You can test the integration locally from the Integration tab.

  1. Click the Kaoto VS Code run run button next to the Camel Route file name.

    The running route is displayed in the Deployments section.

    The Route is launched locally through Camel CLI. You can view the output in the Terminal window at the bottom of the window.

    The integration is launched in Dev Mode. Changes done in the editor or to the source code are reloaded when save the integration.

  2. To control the run, hover over the route in the Deployments section to show the stop and pause buttons.
4.3.1.2.2. Accessing the Source Code

You can access the source code it via the default Visual Studio Code Text Editor, in either of two ways:

  1. Use the Open Source Code toggle button in the top right of the Kaoto editor.
  2. Open the context menu on the integration file tab and choose Reopen Editor with.
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. Explore our recent updates.

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.

Theme

© 2026 Red Hat
Back to top