Use Camel’s fast prototyping using low-code UI and commands to build your integration flows and deploy them on OpenShift.
This hands-on lab is based on the following blog article in Red Hat Developers:
The sequence diagram below illustrates the flow you’re about to create.
The Camel integration will expose an HTTP entry point, and upon client requests, it’ll fetch XML data from a (simulated) legacy backend, transform its response into JSON, and return it to the client application.
Assuming you have followed the article’s instructions, you should be all set to get hands-on with Camel in the OpenShift Dev Spaces workspace.
If you haven’t used Apache Camel before, or haven’t played with recent versions and tools, it’s important you read below all the pieces that are at play, and understand they are conceived to converge into providing a unified development experience.
To briefly introduce the set of tools you’re about to use, here’s a list of the components that will help you along the way:
-
Dev Spaces / VS Code: the IDE you’ll be using to create the Camel processes.
-
Apache Camel: the integration framework you’ll use packed with Enterprise Integration Patterns and Components (connectors).
-
Kaoto: visual editor for Apache Camel to create your Camel routes and processes in VS Code.
-
Camel JBang: Camel CLI (command line interface) designed to boost prototyping and accelerate your work to create, test and deploy your applications.
-
Quarkus: The runtime used by Camel to deploy your integration processes on OpenShift
-
OpenShift: Kubernetes environment where you will deploy your Camel project.
-
OpenShift client: OpenShift’s CLI (command line interface) to help users manage projects in the environment.
One big highlight of the exercises you’re about to embark on is that although Apache Camel is Java based, you won’t see a single line of Java, nor have to define or manage dependencies. Those concerns are kept hidden to allow the developer become more productive by focussing on the business case at hand.
Note
|
It goes without saying that at any moment in time Java code can be injected within your Apache Camel processes to incorporate the custom handling you need. Apache Camel excels in this respect thanks to its open framework architecture and extensibility. |
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
Before we start real work, let’s prepare the equipment before riding the Camel.
Tip
|
Ignore this step if auto-save is already enabled in your environment. |
-
Toggle auto-save on (✓)
You’ll be making live code changes which Camel can pick up in real time. When the file is saved Camel hot-reloads the changes.
To speed up hot-reloads, toggle (✓) auto-save in your editor, as illustrated below:WarningThe auto-save option in the menu does not always show when it’s active/inactive. If you see in your editor’s file tab a permanent white dot ⭘
when you make changes, it means auto-save is OFF.
You’ll use command actions all along the lab.
To execute commands, perform the steps described below, as illustrated:
-
Click the button Copy to clipboard
-
Paste the command in the terminal:
-
on Linux: Ctrl+Shift+v
-
on Mac: ⌘+v
-
-
Try it with:
echo "this is a copy/paste test"
WarningIt’s been reported that these key-combos not always work. Your machine may not respond to the above descriptions. Please try other key or mouse click alternatives, for example, right-click, or middle-click. -
If the paste action fails and you see DevSpaces showing the following notification:
Find in your web browser’s settings where to enable clipboard permissions. The image below shows how to enable them using Chrome:
-
Create a working folder
Execute the commands below to create a new directory from where you can work and is visible in your project explorer:
mkdir lab && cd lab
-
Set your working project in OpenShift
Make sure your CLI
oc
client (OpenShift client) points to your personal Developer Sandbox project (aka namespace):oc project $WORKSPACE_NAMESPACE
NoteThe Developer Sandbox only allows 1 project (namespace) per user. The command above should output something similar to:
Already on project "<your-username>--dev" on server "https://172.30.0.1:443".
WarningNot specifying your target project (namespace) in OpenShift may result in a deployment failure.
If you have a wide monitor, or can organise your browser tabs in a multi-monitor configuration, it is mostly recommended to position your DevSpaces view and your lab instructions side by side, as per the image below:
You’re now all set and ready start riding the Camel.
Is your terminal open and located in your lab
directory?
👍 You’re ready to roll!
Review the instructions above and ensure you run the setup
script.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
This section introduces you to Camel JBang. You will use it to create your base Camel route and explore some of things you can during the development phase.
-
Create your initial integration definition
Make sure you’re working from your
lab
directory:cd /projects/devsandbox-camel/lab
To swiftly create a skeleton Camel route definition, we can use the
camel
client ( Camel JBang client) from the terminal. Execute the following command:camel init user.camel.yaml
The above command initialises a YAML-based Camel definition. Other languages, like Java and XML, are also supported.
-
Open the route in the visual editor
You’ll find your newly created integration file under the following path in your project explorer:
Click on the Camel source file to display it in Kaoto (Camel's visual editor).
The visual editor will show you the default Camel route initialised in step 1, consisting in a timer-to-log processing flow that generates an event every second. Each execution defines a payload (body) and writes it to log.
-
Run the integration with:
camel run *
Notethe *
indicates to load all source files in the folder.After Camel finishes the start up phase, you’ll see a new trace every second, similar to:
2024-10-24 07:21:27.941 INFO ... : Hello Camel from route1 2024-10-24 07:21:28.941 INFO ... : Hello Camel from route1 2024-10-24 07:21:29.941 INFO ... : Hello Camel from route1
To quickly illustrate another useful feature, Camel JBang includes a web based Developer Console.
Stop Camel with Ctrl+c.
And activate the Developer Console using the flag --console
as per the command below:
camel run * --console
Dev Spaces will prompt you to open the port 8080
.
Do so and, in your browser’s address bar, change the URL’s path to the following one:
-
/q/dev
Note
|
Make sure your browser uses plain http:// ( |
Follow the actions illustrated below to open in a new browser tab:
You’ll find a ton of information you can access.
Try for example:
-
top: Display the top routes
When refreshing the page after a few LLM interactions, it should show something similar to:
Top Routes: Route Id: route1 From: timer://yaml?period=1000 Source: file:user.camel.yaml:1 Total: 73 Failed: 0 Inflight: 0 Mean Time: 0ms Max Time: 8ms Min Time: 0ms Last Time: 0ms Delta Time: 0ms Total Time: 8ms
Another console option you can look at is:
-
source: Dump route source code
It will render the source code of your Camel route in YAML DSL:
Source: Id: route1 Source: file:user.camel.yaml:1 #1 - from: #2 uri: "timer:yaml" #3 parameters: #4 period: "1000" #5 steps: #6 - setBody: #7 simple: "Hello Camel from ${routeId}" #8 - log: "${body}"
The examples from above show cool features (out of many) Camel JBang includes.
Feel free to explore more by reading its documentation page.
Tip
|
You can always invoke Camel JBang's help command, from the terminal, to discover all options and flags available:
You also have more granular help per-command. For example, try the following:
|
Is your base route created and have you seen other Camel JBang options?
👍 You’re ready to roll!
Please review the steps of this chapter and try again.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
This section shows you to prototype your project in fast iteration cycles. Camel JBang’s provides a 'developer mode' that allows it to detect and apply on-the-fly any changes you perform.
To make the example interesting, the service you will create will operate as an adaptation layer, collecting data in XML format from a remote server and transforming it to JSON. This is a very typical use case where modern API façades serve data obtained from legacy systems.
Here’s again the sequence diagram illustrating the process you’re about to create.
Follow the commands below:
-
If you haven’t done so yet, stop Camel with Ctrl+c.
-
Run the integration in 'developer mode':
camel run * --dev
Notethe --dev
flag activates the developer mode. -
Start making changes in the Camel route.
Because you’re running Camel in developer mode, every change you do in the editor will trigger a hot-reload and automatic restart.
Update the
timer
definition.
Look at the figure below and follow these steps:-
Click the timer activity to open the configuration pane.
-
Click All (properties).
-
Use the filter
repeat
to search and find properties. -
Set the
repeatCount
property to 1. -
Close the configuration pane.
In the logs, you will see Camel react by restarting and executing the route only once, because
repeatCount
was set to 1:2024-10-24 10:22:23.443 INFO ... : Routes reloaded summary (total:1 started:1) 2024-10-24 10:22:23.443 INFO ... : Started route-4178 (timer://yaml) (source: user.camel.yaml:4) 2024-10-24 10:22:24.442 INFO ... : Hello Camel from route-4178
-
-
Define an HTTPS call
-
Copy the endpoint URL below:
https://random-data-api.com/api/v2/users?response_type=xml
NoteThe parameter response_type
tells the server to return the data in XML format. -
Look at the figure below and follow these steps:
-
Click the 3 dots ⋮ in
setBody
. -
Click ⟳ Replace.
-
Use the filter
https
to search and find the component. -
Select the HTTPS component.
-
Click on the HTTPS step.
-
Paste the URL (you copied above) in the
Http Uri
property. -
Close the configuration pane.
In the logs, you will see Camel reacting and fetching an XML response from the backend, similar to the sample lot traces below:
... : Routes reloaded summary (total:1 started:1) ... : Started route-4178 (timer://yaml) (source: user.camel.yaml:4) ... : <?xml version="1.0" encoding="UTF-8"?> <hash> <id type="integer">9582</id> <uid>837ec527-7925-4904-84ac-8b9113c2dbd8</uid> <password>iobemgl1ZH</password> <first-name>Carl</first-name> <last-name>Auer</last-name> <username>carl.auer</username> <email>[email protected]</email> ...
-
-
-
Define an HTTP listener
Now, expose the process as a service. Replace the Timer event producer with an HTTP listener.
Look at the figure below and follow these steps:
-
Click the 3 dots ⋮ in
timer
. -
Click ⟳ Replace.
-
Use the filter
platform-http
to search and find the component. -
Select the Platform HTTP card.
-
Click on the
platform-http
step. -
Set the Path property to:
Important/user
-
Close the configuration pane.
In the logs, you will see Camel reacting with traces similar to:
... : Routes reloaded summary (total:1 started:1) ... : Started route-4178 (platform-http:///user) (source: user.camel.yaml:5)
NoteIn contrast with previous updates, this time no execution takes place as Camel waits for HTTP requests to comes in. -
-
Clean incoming HTTP headers
To ensure the process cleanly calls the HTTP endpoint and to prevent header propagation, you need to include a step to clean the incoming HTTP headers.
Look at the figure below and follow these steps:
-
Click the 3 dots ⋮ in
platform-http
. -
Click + Add step.
-
Use the filter
removeheaders
to search and find the component. -
Select the Remove Headers card.
-
Click on the
removeHeaders
step. -
Set the Pattern property to
*
. -
Close the configuration pane.
At this point your Camel route should look in Kaoto as the picture below:
In the logs, you should see Camel having reacted from the updates above and showing the following traces:
... : Routes reloaded summary (total:1 started:1) ... : Started route-4178 (platform-http:///user) (source: user.camel.yaml:5)
-
-
Test the listener
To validate what you’ve done so far, test the listener from a new terminal. Choose the Split option from the current terminal’s top right corner, as shown below:
From the new terminal, run the following cURL command to test your service:
curl -s http://localhost:8080/user | bat -pP -lxml
NoteThe command also includes a pipe to colorize the XML output for better reading. The invocation should return an XML payload similar to:
<?xml version="1.0" encoding="UTF-8"?> <hash> <id type="integer">9867</id> <uid>f7907251-4336-40d3-8502-a1021a1a10b4</uid> <password>KsbN09mckU</password> <first-name>Danny</first-name> <last-name>Stehr</last-name> <username>danny.stehr</username> <email>[email protected]</email> ...
So far so good.
-
Apply XML to JSON transformation
Keep iterating the prototype by introducing XML to JSON translation.
In Camel there are many strategies available to convert XML into JSON. In this case you will use the Marshal/Unmarshal EIP to update the flow. You do it by adding two extra steps to the process: first Unmarshal (XML) and then Marshal (JSON).
-
Start by unmarshalling the XML data
Look at the figure below and follow these steps:
-
Right-click on the
https
step. -
Select the ↓ Append option.
-
Use the filter
unmarshal
to search and find the component. -
Select the Unmarshal card.
-
Click on the
unmarshal
step. -
Select the Jackson XML Data Format.
-
Close the configuration pane.
-
-
Then marshal to JSON
Look at the figure below and follow these steps:
-
Right-click on the
unmarshal
step. -
Select the ↓ Append option.
-
Use the filter
marshal
to search and find the component. -
Select the Marshal card.
-
Click on the
marshal
step. -
Select the Json Data Format.
-
Close the configuration pane.
-
At this point your Camel route should look in Kaoto as the picture below:
In the logs, you should see Camel having reacted from the updates above and showing the following traces:
... : Routes reloaded summary (total:1 started:1) ... : Started route-4178 (platform-http:///user) (source: user.camel.yaml:5)
-
-
Test the XML to JSON transformation
Test the Unmarshal/Marshal steps with the command below:
curl -s http://localhost:8080/user | jq
NoteThe command also includes a pipe to colorize the JSON output for better reading. The invocation should return JSON data, similar to:
{ "phone-number": "+63 890.053.3511 x6876", "address": { "city": "Feestport", "street-name": "Cecil Camp", "street-address": "12806 Abbott Summit", ...
Did your last curl command return JSON data?
Well done !!
Go back in your footsteps and review the actions.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
You’ve completed your prototype, it is time to deploy it.
The Camel CLI (Camel JBang) includes a Kubernetes plugin that makes it very easy to deploy your application on Openshift.
Camel JBang and the Kubernetes plugin will do all the work for you. Your code gets analysed and all the necessary dependencies automatically detected and downloaded, then containerised and deployed on Openshift.
Follow the commands below:
-
If you haven’t done so already, stop Camel with Ctrl+c.
-
Make sure you’re working from your
lab
directory:cd /projects/devsandbox-camel/lab
-
Run the following command from your terminal to deploy your application:
camel kubernetes run * --cluster-type=openshift --trait route.enabled=true --trait route.tls-termination=edge
Note-
The
--cluster-type
flag indicates the Kubernetes flavour of your target environment. -
The
route.enabled=true
trait indicates to create an Openshift route to allow external access. -
The
route.tls-termination=edge
trait enables secure HTTP (HTTPS).
The execution will export the code into a Camel Quarkus application and deploy it on Openshift.
NoteBe patient, the execution may take 3 to 5 minutes the first time as Camel analyses the code, downloads required dependencies, builds and deploys the application. In the logs you’ll see following traces:
... Exporting application ... Deploying to Openshift ... Invalid AnsiLogger Stream -> Swapping to default sdt out logger. [INFO] Adding existing Deployment with name: user. [INFO] Adding existing Service with name: user. [INFO] Adding existing Route with name: user.
-
You can inspect when your deployment is ready by issuing the following command:
watch oc get deployments
Your Camel application will be ready when user
shows READY 1/1
, similar to the output below:
NAME READY UP-TO-DATE AVAILABLE AGE user 1/1 1 1 4m25s workspace7c6e32fd061c4d25 1/1 1 1 17m
Tip
|
Stop the watch with Ctrl+c. |
You can also visually inspect your pod by opening Openshift’s Developer Console following the actions below:
-
At the bottom-left of your screen, click the >< button.
-
Then at the top, select:
-
Dev Spaces: Open OpenShift Console
-
-
If a list of namespaces shows, select your namespace.
-
Your Camel Quarkus Application is labelled with
user
.
Do you see your Camel application deployed in the Developer Console?
Well done !!
Review the instructions and try again.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
-
Because the application has been deployed alongside your DevSpaces workspace pod (see picture below), in the same OpenShift namespace, you can call it from your same subnet.
Use the following command to test the deployed application:
curl -s http://user:80/user | jq
Noteyou can directly call the service user
on port 80 because the pod runs in the same namespace.Again, you should see a similar JSON response as per your previous test run locally.
{ "phone-number": "+375 1-790-160-4090 x0991", "address": { "city": "East Justinafurt", "street-name": "Jerde Club", "street-address": "860 Yaeko Ramp", ...
-
When the Camel application was deployed using the Kubernetes plugin, the command included the
route.enabled
setting to expose the service for external consumption.Use the route to call the service as if it was an external call. Follow the commands below:
echo https://`oc get route user -o jsonpath={.spec.host}`/user
Then, use the URL generated on a browser tab or click as indicated, like in the image below:
You should see in your browser the JSON response obtained, similar to:
TipWhen using Chrome, you can tick on the Pretty print check box to beautify the JSON response
Did you succeed to invoke the user
service as an external consumer?
Well done !!
Make sure your route exists, and you’re using the /user
path.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
The list below summarises the main resources created by the Camel Kubernetes plugin during the deployment process on OpenShift:
-
an ImageStream: your application containerised.
-
a Deployment: your application deployment definition
-
a Service: a Kubernetes service to access your Camel integration.
-
a Route: an OpenShift route to expose the service to external clients.
If you wanted to undeploy your application to free up resources in the environment you would need to manually delete the items on the list above, plus additional residual (not listed) resources.
Thankfully, the Camel Kubernetes plugin makes it super simple to undeploy your integration in one single command.
Execute the command below to remove user
from your namespace:
camel kubernetes delete user
In your terminal, you should see an execution output similar to:
Deleted: Service 'user' Deleted: Imagestreams 'openjdk-17' Deleted: Imagestreams 'user' Deleted: Buildconfigs 'user' Deleted: Deployments 'user' Deleted: Routes 'user'
Verify your deployment has been deleted by issuing the following Openshift command:
oc get deployments
The command should return your workspace deployment only:
NAME READY UP-TO-DATE AVAILABLE AGE workspace7c6e32fd061c4d25 1/1 1 1 16m
Did you manage to successfully undeploy your user
Camel integration?
Well done !!
Review the instructions in this chapter and try again.
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
For those thirsty of knowledge willing to learn more about other Camel use cases we strongly recommend to try out another exciting tutorial.
Follow the link below to visit the introductory article that will take you to the learning material:
Warning
|
Before you go, please make sure you clean your sandbox namespace to free up resources. Click Next for detailed instructions.
|
kbd { color: black; background-color: lightgrey; border: 1px solid black; box-shadow: 0px 1px black; font-size: .85em; line-height: .85em; display: inline-block; font-weight: 600; letter-spacing: .05em; padding: 3px 5px; white-space: nowrap; border-radius:5px; }pre {background-color: black; color: white}
Before you go, make sure you leave your account clean from artifacts so that you can play with other tutorials in the future or simply do solo experimentation.
When you’re done playing with the workspace, follow the guidance below to delete it entirely from the environment.
Warning
|
Your VSCode environment along with these lab instructions will be deleted from your sandbox. |
First, stop your workspace by following the actions below:
-
At the bottom-left of your screen, click the >< button.
-
Then at the top, select:
-
Dev Spaces: Stop Workspace
-
Stopping your workspace will make your browser switch to the Dev Spaces dashboard.
From the dashboard, follow the steps indicated below:
-
Click Workspaces, from the left menu.
-
Tick the checkbox for
devsandbox-catalog-ai-labs
. -
Click the button
Delete
.
Is your namespace clean from artifacts?
You’ve successfully cleaned up your namespace !!
Review the instructions in this chapter and try again.