This snippet of code defines a Route which receives a list of country id and dispatch to the corresponding country.
val routeDef = new BabelRouteBuilder {
val splitString = (body: String) => body.split(",").toList
val isForSwitzerland = (msg: Message[String]) => msg.body.fold(false)(_ == "CH")
val isForGermany = (msg: Message[String]) => msg.body.fold(false)(_ == "D")
val filterGermanyErrors = (msg: Message[String]) => {
!msg.headers.contains("GermanyCurrencyFailure")
}
val isForFrance = (msg: Message[String]) => msg.body.fold(false)(_ == "F")
from("direct:input").as[String]
.processBody(splitString)
.splitBody(list => list.iterator)
.processBody(string => string.toUpperCase)
.choice {
c =>
c.when(isForSwitzerland).to("mock:switzerland")
c.when(isForFrance).to("mock:france")
c.when(isForGermany).filter(filterGermanyErrors).to("mock:germany")
}
.to("mock:output")
}