Skip to content

Instantly share code, notes, and snippets.

@takscape
Created September 3, 2016 05:18
Show Gist options
  • Save takscape/b5c630ae2c821f442745a02c7eb67841 to your computer and use it in GitHub Desktop.
Save takscape/b5c630ae2c821f442745a02c7eb67841 to your computer and use it in GitHub Desktop.
package ninja.util.camel.example
import org.apache.camel.CamelContext
import org.apache.camel.Exchange
import org.apache.camel.ProducerTemplate
import org.apache.camel.builder.ExchangeBuilder
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
fun CamelContext.addRoute(f : RouteBuilder.() -> Unit) {
this.addRoutes(object : RouteBuilder() {
override fun configure() { this.f() }
})
}
fun ProducerTemplate.sendExchange(f : ExchangeBuilder.() -> Unit) : Exchange {
val builder = ExchangeBuilder(camelContext)
builder.f()
return this.send(builder.build())
}
fun main(args: Array<String>) {
val ctx = DefaultCamelContext()
ctx.addRoute {
from("direct:start")
.to("log:messages?level=ERROR")
}
ctx.start()
val tmpl = ctx.createProducerTemplate()
tmpl.setDefaultEndpointUri("direct:start")
tmpl.sendExchange {
withBody("This is my first exchange.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment