Apache Camel is an integration framework that allows to integrate different systems using various protocols and technologies. By default, there already a lot of pre-built connectors, components, and processors that make it easy to integrate different systems and applications.
Apache Camel works by create a route to specify how messages should be processed and passed between endpoints. a route usually starts with source, and ends with a destination, then we can manipulate data between source and destination using pre-built processor that Camel has.
There is some ways to use Apache Camel, but in this documentation, we will use Camel K which deployed in kubernetes cluster, which we can easily interact with it using API, and it will treat a route as a dedicated pod.
- Install Camel K First on a cluster, can use minikube, or k3d to create a cluster on top of docker
- Install Kamel, it's a client app that will be used to interfacing with Camel K in a Kubernetes cluster
- Test if it's work by running a "Hello World" for Integration
- If the log show like this, then it's good to go
Camel uses a Java Domain Specific Language or DSL to create Routes, we can see the DSL that are fully supported by Camel here. But there is also some DSL that are still in experiment like JavaScript DSL, in this documentation, we're going to use JavaScript DSL.
- For starter, we can use
timer
component to run our integration with interval time, says to run it every 2 seconds, and log the resultand the result will be like thisfrom('timer:tick?period=2000') .process((e) => { e.getIn().setBody('Hello Camel K!') }) .to('log:info') .to('log:warning')
- We can use
transform
to manipulate the data inside process before it reached destinationAnd we can see the result here, before transform is an array, and after transform, we only take second index to be printedfrom('timer:tick?period=2000') .process((e) => { const data = ['Hello', 'Camel', 'K!'] e.getIn().setBody(data) }) .to('log:info-before-transform') .process((e) => { const body = e.getIn().getBody(Java.type('java.lang.String[]')) e.getIn().setBody(`Hai ${body[1]}`) }) .to('log:info-after-transform')
- Using pre-built component to integrate with services