Created
September 3, 2016 05:18
-
-
Save takscape/b5c630ae2c821f442745a02c7eb67841 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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