Skip to content

Instantly share code, notes, and snippets.

@marcelmaatkamp
Created April 25, 2010 15:36
Show Gist options
  • Save marcelmaatkamp/378486 to your computer and use it in GitHub Desktop.
Save marcelmaatkamp/378486 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
import org.apache.camel.*
@Grapes([
@Grab('org.springframework:spring:2.5.6'),
@Grab('org.apache.camel:camel-core:2.2.0'),
@GrabConfig(systemClassLoader = true)
])
class QuoteServiceBean {
public String usStock(String symbol) {
"${symbol}: 123.50 US\$"
}
public String hkStock(String symbol) {
"${symbol}: 90.55 HK\$"
}
}
class MyRouteBuilder extends org.apache.camel.builder.RouteBuilder {
void configure() {
from("direct://quote").choice()
.when(body().contains(".HK")).bean(QuoteServiceBean.class, "hkStock")
.otherwise().bean(QuoteServiceBean.class, "usStock")
.end().to("mock://result")
from("direct://xmlquote").transform()
.xpath("//quote/@symbol", String.class)
.to("direct://quote")
}
}
ctx = new org.apache.camel.impl.DefaultCamelContext()
ctx.addRoutes new MyRouteBuilder()
ctx.start()
p = ctx.createProducerTemplate()
p.sendBody("direct:quote", "00005.HK")
p.sendBody("direct:xmlquote", "<quote symbol='IBM'/>")
p.sendBody("direct:xmlquote", "<quote symbol='00005.HK'/>")
e = ctx.getEndpoint("mock://result")
e.exchanges.each { ex ->
println "INFO> in.body='${ex.in.body}'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment