Featured image for Apache Camel K with Red Hat OpenShift.

You can now try Camel K in the Developer Sandbox for Red Hat OpenShift, an OpenShift environment you can access for a free, hands-on experience in building and deploying cloud-native applications quickly. This article will guide you to the Developer Sandbox and through a Camel K integration in a fully web-based experience—no local installs needed.

If you are unfamiliar with Camel K, it is a subproject of Apache Camel, which many know as the Swiss Army knife of integration. Camel K simplifies the process of running cloud-native integration flows in Kubernetes environments.

What’s so special about Camel K?

Many organizations and developers implement microservices with varied languages and frameworks, but they usually forget the existence of purpose-built technologies such as Apache Camel, packed with hundreds of connectors and out-of-the-box patterns to resolve typical and challenging integration scenarios, such as content-based routing, splitting or data aggregation, protocol bridging, data transformation, and so on.

Camel K was designed to encapsulate the key concepts of running integrations on containers, providing a significant degree of automation to simplify the process of creating, building, deploying, and operating integration flows in Kubernetes environments.

Usually, applications are defined in a complex project tree and include dependency descriptors to incorporate libraries necessary to run the application. Camel K, on the other hand, aims to simplify the project to let the developer focus on the process flow definition. It automatically analyzes the code to find needed dependencies and only requires the essential flow definitions and resources from the developer.

Access the Developer Sandbox

Follow these instructions to get started in the Developer Sandbox: How to access the Developer Sandbox for Red Hat OpenShift

Once you have your browser connected to the Developer Sandbox console, you’ll be all set to start the first part of this article’s tutorial.

Part 1: Roll the dice

The most straightforward way to get started with Camel K is from the Developer view. Follow the instructions below to deploy a “Hello world” example.

From the Developer view, click +Add in the left menu, and scroll down to the Developer Catalog to find the Operator Backed category, as shown in Figure 1.

add operator
Figure 1: Add 'Operator Backed' from the Developer Catalog.

Locate the Integration resource in the catalog, as illustrated in Figure 2:

  • Use the filter (type “integration”)
  • Click on the Integration tile, then click the blue Create button that appears from the right.

select integration
Figure 2: Find the Integration resource.

Click on the Configure via YAML view radio button. You will then be presented with a definition screen similar to the one shown in Figure 3.

YAML view
Figure 3: YAML view.

By selecting the YAML view, the interface lets you edit the definition and create the integration directly on the screen. This is a manual procedure that is very helpful when playing with the technology for the first time.

The default Camel route definition is very simplistic; let’s make it a bit more interesting so that you can start experiencing the Camel K operator in action.

Replace the default Camel route (from definition) with the following snippet:

    - from:
        uri: 'platform-http:/roll-dice'
        steps:
          - set-body:
              simple: 'roll: ${random(1,6)}'

In the preceding code, the from element exposes an HTTP entry point for a service called roll-dice that will serve random numbers from 1 to 6 when clients submit HTTP requests.

Click Create.

When you create an integration as just described, the definition gets stored in your OpenShift project (namespace). Behind the scenes, the Camel K operator, deployed elsewhere, has visibility and picks up your definition to trigger a build and deployment on your project. This process takes some time.

To monitor the state of the integration deployment, open a terminal from where you can obtain information from the environment via the command line. Click the terminal icon at the top of your screen and then click the Start button below to initialize the terminal, as shown in Figure 4.

Open the terminal for Camel K
Figure 4: Initialize the terminal.

When you start the terminal, a new pod deploys. This is where your terminal is running.

Work terminal
Figure 5: Terminal running.

On your terminal, type:

oc get integration -w

The flag -w indicates to watch the resource for changes.

As the work progresses, its state will transition from Building Kit to Deploying to Running.

You should see an output similar to the following:

bash-4.4 ~ $ oc get integration -w
NAME      PHASE          KIT                        REPLICAS
example   Building Kit   kit-cdl6pa788ih7pmdvn6c0
example   Deploying      kit-cdl6pa788ih7pmdvn6c0
example   Running        kit-cdl6pa788ih7pmdvn6c0   0
example   Running        kit-cdl6pa788ih7pmdvn6c0   1
example   Running        kit-cdl6pa788ih7pmdvn6c0   1
example   Running        kit-cdl6pa788ih7pmdvn6c0   1

 

When the deployment completes, a new pod will run your integration definition:

Pod running the example
Figure 6: Pod running the example.

What’s interesting in this deployment is that the Camel K operator has the intelligence to recognize you’re exposing an HTTP endpoint and automatically deploys a Kubernetes service named example.

To test the service from within OpenShift, you can invoke it from the terminal. Enter the following cURL command and execute:

curl http://example/roll-dice

The command should return the value produced by the Camel integration. Executing it multiple times will produce random numbers from 1-6, simulating the dice rolling each time.

By default, the Developer Sandbox does not expose the service automatically to external consumers. If you want the service to be externally accessible, you can simply enable an OpenShift route by running the following command:

oc expose service example --path=/roll-dice

The command above uses the OpenShift client oc to create a route that points to your new Camel example service, to expose to the external world.

Now you can also call the roll-dice service from your browser as if you were an external consumer. Notice the little icon attached to the Camel’s pod round graphic; click on it.

Camel K pod
Figure 7: Camel example service.

If your browser renders "Resource not found" or another error message, make sure your address bar uses http (not HTTPS), and include the service path /roll-dice at the end of the URL, similar to:

http://...<long address value here>.../roll-dice

In your browser, it should look similar to Figure 8.

browser roll dice
Figure 8: The browser.

If you click the Reload button several times, you’ll see different values displayed.

When you’re done, to clean up your working project, delete your integration with the simple command shown below:

oc delete integration example

You also need to delete the route you manually created by executing:

oc delete route example

Part 2: Inside OpenShift Dev Spaces

If you want to play with Camel K in a more traditional developer workflow using a code editor and a terminal, the Developer Sandbox ships with an entire web-based IDE called Red Hat OpenShift Dev Spaces (formerly Red Hat CodeReady Workspaces).

Set up your dev environment with the Camel tutorials

The animated sequence in Figure 9 illustrates the actions to follow to open your development environment along with your tutorial instructions.

gif to open dev tutorial
Figure 9: The Dev Spaces UI.

Follow these steps:

  1. From the web console, click the Applications icon as shown in Figure 9 (marked 1).
  2. Select Red Hat OpenShift Dev Spaces (2).
    You will be prompted to log in and Authorize Access; select the "Allow selected permissions" option.
  3. When the Create Workspace dashboard in OpenShift Dev Spaces opens, copy the snippet below:

    https://github.com/RedHat-Middleware-Workshops/devsandbox-camel.git

    Then, paste it into the Git Repo URL field (3).

  4. Click Create & Open (4).
  5. When the workspace finishes provisioning and the IDE opens, click the deployable Endpoints accordion (5).
  6. Then, click on the icon (6), which opens the tutorial in a new browser tab.
  7. Choose the tutorial indicated in the next section.

Start the Camel K tutorial

Select the Camel K - User Demo tile, highlighted in Figure 10.

Camel K tutorial
Figure 10: Locating the Camel K tutorial.

When you click on the tile, the Solution Explorer will show the lab introduction and the exercise chapters included, which you should be able to complete in around 15 minutes.

The aim of this use case demo is to help you get started with the basics of Camel K and play in the Developer Sandbox. For that reason, the use case selected is simple and friendly. The sequence diagram in Figure 11 illustrates the flow you’re about to create; you’ll get to see for yourself how little effort is required to complete it.

sequence diagram
Figure 11: The Camel K flow.

Enjoy the Camel ride!

More Apache Camel resources

This article ends here, but this should only be the start of your journey with Apache Camel. The Developer Sandbox for Red Hat OpenShift gives you the opportunity to play on a Kubernetes-based application platform with an integrated developer IDE (OpenShift Dev Spaces).

With your browser alone, you can quickly complete the Camel K lab and see by yourself how simply Camel resolves a typical use case and how easy it is to test, containerize, and run applications in OpenShift.

Camel K is a convenient way to build and deploy integrations with Apache Camel. Its simplicity and ease of use accelerate developers. You might, however, find other Camel runtimes better suited for more advanced use cases. We encourage you to check out the resources below to learn more about Camel K and explore different ways you can build applications with Apache Camel:

Last updated: October 6, 2023