Writing Integrations in JavaScript

The JavaScript DSL is current in preview support level.

An integration written in JavaScript looks very similar to a Java one:

hello.js
const Processor = Java.extend(Java.type("org.apache.camel.Processor"));

function proc(e) {
    e.getIn().setBody('Hello Camel K!')
}

from('timer:tick')
    .process(new Processor(proc))
    .to('log:info')

To run it, you need just to execute:

kamel run hello.js

For JavaScript integrations, Camel K does not yet provide an enhanced DSL but you can access to some global bounded objects such as a writable registry and the camel context so to set the property exchangeFormatter of the LogComponent as done in previous example, you can do something like:

l = context.getComponent('log', true, false)
l.exchangeFormatter = function(e) {
    return "log - body=" + e.in.body + ", headers=" + e.in.headers
}