Writing Integrations in Kotlin

An integration written in Kotlin looks very similar to a Java one except it can leverages Kotlin’s language enhancements over Java:

    .process { e -> e.getIn().body = 'Hello Camel K!' }

Camel K extends the Camel Java DSL making it easier to configure the context in which the integration runs using the top level context block

context {
  // configure the context here

At the moment the enhanced DSL provides a way to bind items to the registry, to configure the components the context creates and some improvements over the REST DSL.

Registry Configuration

The registry is accessible using the registry block inside the context one:

context {
    registry {
        bind("my-cache", Caffeine.newBuilder().build()) (1)
        bind("my-processor", processor { (2)
            e -> e.getIn().body = "Hello"
        bind("my-predicate", predicate { (3)
            e -> e.getIn().body != null
1 bind a simple bean to the context
2 define a custom processor to be used later in the routes by ref
3 define a custom predicate to be used later in the routes by ref

Components Configuration

Components can be configured within the components block inside the context one:

context {
    components {
        component<SedaComponent>("seda") { (1)
            queueSize = 1234
            concurrentConsumers = 12

        component<SedaComponent>("mySeda") { (2)
            queueSize = 4321
            concurrentConsumers = 21

        component<LogComponent>("log") { (3)
           setExchangeFormatter {
               e: Exchange -> "" + e.getIn().body
1 configure the properties of a component whit type SedaComponent and name seda
2 configure the properties of a component with type SedaComponent and name mySeda, note that as mySeda does not represent a valid component scheme, a new component of the required type will be instantiated.
3 configure the properties of the component whit name log

As for Groovy, you can provide your custom extension to the DSL

Rest Endpoints

Integrations’s REST endpoints can be configured using the top level rest block:

rest {
    configuration { (1)
        host = "my-host"
        port = "9192"

    path("/my/path") { (2)
        // standard Rest DSL
1 Configure the rest engine
2 Configure the rest endpoint for the base path '/my/path'