How to create a Camel integration and deploy it as a serverless service

This activity, created by Kah Hoe Lai, walks through how to create an Apache Camel integration and deploy it as a serverless service using the VS Code extension Karavan.

In the last lesson, you successfully defined your Camel project. Now let's create the Camel route.

What you need 

  • A workspace in Red Hat OpenShift Dev Spaces
  • A no-cost Developer Sandbox for Red Hat OpenShift environment

What you will learn

  • How to create an integration routeccess the Developer Sandbox
  • How to create a REST API service

Create the Camel integration route

  1. From the Projects menu icon, select Karavan: Create Integration from the context menu (Figure 16).
    The context menu for Karavan: Create Integration.
    Figure 16: The context menu for Karavan: Create Integration.
  2. Enter hello-world as the integration name (Figure 17).
    The integration name.
    Figure 17: The integration name.
  3. A new file with the name hello-world-camel.yaml has now been created. Inside the hello-world camel project, select the Routes tab, then Create route (Figure 18).
    The Create route button.
    Figure 18: The Create route button.
  4. Under the Components tab, search for the word direct (Figure 19).
    The Direct components under the Components Tab.
    Figure 19: The Direct components under the Components Tab.
  5. Click on the Direct icon. Enter my-internal-route to the internal route field (Figure 20).
    The Direct component created and name parameter for Direct component.  ​
    Figure 20: The Direct component created and the name parameter for Direct component. ​
  6. Add more steps to the route. Click the + icon under the Direct Route (Figure 21).
    The + icon below Direct component.
    Figure 21: The + icon below Direct component.
  7. Choose the Routing tab, then search for the word log (Figure 22).
    Choose the Routing tab, then search for “log”.
    Figure 22: Choose the Routing tab, then search for “log”.
  8. Configure the Log to print message ${body} (Figure 23).
    Configure the log.
    Figure 23: Configure the log.

Create a simple REST API

  1. Click on the REST tab, then select Create service (Figure 24).
    The +Create service button under the REST tab.
    Figure 24: The +Create service button under the REST tab.
  2. Select Add method (Figure 25).
    The +Add method button for REST.
    Figure 25: The +Add method button for REST.
  3. Choose the Post method (Figure 26).
    The Post method for HTTP method.
    Figure 26: The Post method for HTTP method.
  4. Link the REST endpoints to the direct route. Inside the setting for the POST method, select To : direct:my-internal-route (Figure 27). This will route the incoming request to my-internal-route.
    The setting for POST method with direct:my-internal-route selected.
    Figure 27: The setting for POST method with direct:my-internal-route selected.
  5. You can inspect the content of the Camel YAML file by double-clicking the hello-world.camel.yaml file in the project explorer. In Figure 28, the IDs are randomly generated.
    Inspect the content of the Camel yaml file.
    Figure 28: Inspect the content of the Camel yaml file.

Congratulations! You have successfully created a Camel route file. Now let's run and test it inside OpenShift.

Previous resource
Install the Karavan extension, then scaffold a new Camel project
Next resource
Run and test inside OpenShift Dev Spaces and deploy it to OpenShift