Graduates versus Camel K

Ally Kouao
7 min readSep 24, 2020

--

Written by Jonny Browning and Ally Kouao

We are two Graduate Solution Architect & Developer Advocates on the Red Hat Graduate Programme. The Graduate Programme places heavy emphasis on training and development, and that is where the ‘Developer Advocate’ part of our role comes in. We get to play around with different technologies, concepts and goals to familiarise ourselves with Red Hat’s offerings. This is so that we can better understand how we can get developers — who are often important stakeholders when it comes to introducing new technologies into an organization — involved and carry on doing what they do best.

What is Camel K?

Hold on. Before we start nattering on about Camel K (and learn while we are at it), let’s start with the basics to ensure that we are on the same page.

What is Apache Camel? According to user documentation, Apache Camel is a versatile open-source integration framework. It empowers developers to define routing and mediation rules (rules for interpretation) in a variety of languages. Outside of the standard boilerplate Java or Spring XML, there are also Domain Specific Languages for the integrations.

Ferraro, N. (2019). Cloud Native Integration with Camel K [Diagram]. Retrieved from https://www.slideshare.net/nicolaferraro/cloudnative-integration-with-camel-k-devnation-london

“How does Camel K come into this?” is the next question you might be asking… don’t fret, we’ve got you. Camel K is a lightweight integration platform based on the Apache Camel framework. It allows integrations to run natively on OpenShift or Kubernetes — the integrations themselves are Kubernetes objects, so there’s no need to create a runtime environment or worry about Maven dependencies, you can just install the operator and start running your integrations! Other benefits of using Camel K on Kubernetes include the ability to scale your integrations using Knative serverless technology, real-time code updates, and the ability to easily scale your integrations as needed.

Camel K makes it simple to get your integrations up and running quickly on Kubernetes. A developer interacts with Kubernetes using the ‘kamel’ command-line tool. The Camel K operator takes care of running the integration code in containers, and managing all the other aspects for you.

Apache Camel K CLI (“kamel”) — a command line interface — is the main tool used by developers to run integrations. It alleviates the pressure on developers to remember the boilerplate needed to instantiate a Camel Route builder; you can create a file with all the boilerplate written for you in several languages, and just focus on writing the integration routes. Kamel is able to push integrations to Kubernetes by pushing the integration code produced locally to Kubernetes as a secret. The secret — which is just data mounted into the container — can be updated at runtime. This means that Kamel CLI can push the new integration data into the secret and have it immediately update. An update to an integration will be demonstrated later on in this blog.

Why do I need Integration?

As recent graduates, we’ve only really worked on fairly small software projects in the past, so we’ve not needed to use integration technologies before. But as software systems get more complex, it becomes more tedious to connect up different parts of the system. For my own projects, I’ve always just written the necessary code into the applications themselves. In reality, organizations have lots of different systems that use all sorts of different protocols and formats, written by different teams within the organization, and many from outside the organization.

The kinds of data transformations that are needed to get these systems playing nicely together are often very similar, or in other words, they tend to follow certain patterns. Common integration patterns include splitters, aggregators and message filters. In fact, there are dozens of these patterns that are used all the time, and they’ve been pulled together into a book — Enterprise Integration Patterns, by Gregor Hohpe and Bobby Woolf.

Example of an integration using Enterprise Integration Patterns. Messages are aggregated from System A and System B, filtered, then re-sequenced, before being sent to System C.

So you have a choice. When you want to stitch together two bits of software using one of these patterns, you can either write your own piece of software to do the translation, or you can use some tried and tested open source components to make your life easier.

The Apache Camel framework is an open source implementation of these patterns. What’s more, Apache Camel has over 300 components for integrating with all kinds of things, such as Salesforce, AWS S3 storage, and Twitter, so you don’t have to navigate these complicated APIs for yourself. As the world moves towards microservices architectures, the complexity of your systems only increases, and the value of Apache Camel and Camel K quickly becomes very clear!

Apache Camel makes it super easy to integrate between external services, thanks to the huge range of components.

Show us, show us!

A beginner’s guide/101 wouldn’t be one without a demo! To get more hands on, we are completing a “hello world” integration. It’s a very simple example — a timer triggers a message every second, the header and body are changed, and the message is sent to a log:

Before we get started, you’ll need an OpenShift cluster, and you’ll need the kamel CLI tool installed on your local machine. You’ll also need either the oc command line tool, or kubectl installed on your local machine.

  1. To ensure that you have kamel installed, type kamel into your terminal. You should see output similar to this:
Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless superpowers.Usage:kamel [command]Use "kamel [command] --help" for more information about a command.

2. Log in to OpenShift using the command line (oc login…), and create a project called “hello-camel-k”:

oc new-project hello-camel-k

3. Upon creating the project namespace, the Camel K is installed using the kamel CLI:

kamel install — skip-operator-setup — skip-cluster-setup — trait-profile OpenShift

4. To verify that the operator was successfully installed, you should observe the following output:

OLM is available in the clusterOLM resources are already available: skipping installationCamel K operator installation skippedCamel K installed in namespace user1-lab-basic via OLM subscription

When the Camel K operator has been installed, it will have created an IntegrationPlatform resource for the project created earlier (hello-camel-k).

5. To verify this, type:

oc get integrationplatform

which will produce the following output if all is well:

NAME      PHASEcamel-k   Ready

6. In VSCode, reproduce a file titled helloworld.java, that contains a simple Camel K integration utilising the timer and log components, that will periodically print a “Hello World…” message in the terminal:

helloworld.java

// camel-k: language=javaimport org.apache.camel.builder.RouteBuilder;public class helloworld extends RouteBuilder {@Overridepublic void configure() throws Exception {     from("timer:java?period=1000&fixedRate=true")       .setHeader("example")         .constant("Java")       .setBody()        .simple("Hello World! Camel K route written in ${header.example}.")       .to("log:info"); }
}

7. The next command requires you to run the class in “dev mode” to be able to see the logs in the integration terminal:

kamel run helloworld.java --dev

And before you know it, the build completes and you will be able to see the Camel integration running and repeatedly printing “Hello World!…” in the terminal window:

[1] 2020-09-21 22:12:42.585 INFO  [Camel (camel-k) thread #0 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello World! Camel K route written in Java.][1] 2020-09-21 22:12:43.585 INFO  [Camel (camel-k) thread #0 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello World! Camel K route written in Java.]...

Another cool thing about Camel K is that, while running in dev mode, the integration code can be changed and Camel K will redeploy the changes automatically. We had to try it out! The logged message was changed from “Hello World!…” to “Camel K est superbe!” — pardon my French!

8. Upon saving the file, the new integration immediately started up in the terminal window, replacing the old one:

[2] 2020-09-21 22:13:37.396 INFO  [Camel (camel-k) thread #0 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Camel K est superbe!][2] 2020-09-21 22:13:38.396 INFO  [Camel (camel-k) thread #0 - timer://java] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: Camel K est superbe!]...

What’s Next?

So there you have it! We’ve just shown a simple example of using Camel K, but there are lots of other scenarios where you might find it useful. How about creating an API for your legacy system? Or synchronising data changes between applications, such as updating an employee’s address? Or even triggering notifications based on events? The possibilities are endless.

Navigate to developers.redhat.com and Red Hat’s dedicated Fuse page to find out more about how Red Hat can help you on your integration journey. If you want to take a closer look at Camel K, why not check out the projects section in the Camel K GitHub repository to keep up to date with the current areas that are being worked on? There are a lot of cool things coming!

--

--