RoutesCamel supports the definition of routing rules using a Java DSL (domain specific language) which avoids the need for cumbersome XML using a RouteBuilder. For example a simple route can be created as follows. RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a").to("queue:b"); } }; As you can see from the above Camel uses URIs to wire endpoints together. FiltersYou can combine simple routes with filters which can be arbitrary Predicate implementations. RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b"); } }; ChoicesWith a choice you provide a list of predicates and outcomes along with an optional default otherwise clause which is invoked if none of the conditions are met. RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a").choice() .when(header("foo").isEqualTo("bar")).to("queue:b") .when(header("foo").isEqualTo("cheese")).to("queue:c") .otherwise().to("queue:d"); } }; Using a custom processorHere is an example of using a custom Processor myProcessor = new Processor() { public void process(Exchange exchange) { log.debug("Called with exchange: " + exchange); } }; RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a").process(myProcessor); } }; You can mix and match custom processors with filters and choices. RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a").filter(header("foo").isEqualTo("bar")).process(myProcessor); } }; InterceptorsHere is an example of adding a few custom InterceptorProcessor interceptor2 = new MyInterceptorProcessor(); RouteBuilder builder = new RouteBuilder() { public void configure() { from("queue:a") .intercept() .add(interceptor1) .add(interceptor2) .target().to("queue:d"); } }; When you start defining and interceptor stack with intercept(), you must follow up with the subsequent .target() so that the target of the interceptor stack is properly registered. |