...
Using Closures in your routes
Groovy closures can be used to write concise implementations of Camel processors, expressions, predicates, and aggregation strategies. It is recommended to keep more complicated implementations of these objects in their own classes, e.g. to be able to test them more easily and not to clutter up your routes with business logic.
Processor Closures
All Java DSL parameters of type org.apache.camel.Processor
can be replaced by a closure that accepts an object of type org.apache.camel.Exchange
as only parameter. The return value of the closure is disregarded. All closures may also refer to variables not listed in their parameter list. Example:
Code Block | ||||
---|---|---|---|---|
| ||||
... private String someValue ... from('direct:test') .process { Exchange exchange -> println (exchange.in.body + someValue) } .process { println (it.in.body + someValue) } // equivalent ... |
Expression Closures
...