Guide to Spring Bean (Content-based Router)

n some scenarios, a single logical process and its implementation (ie. price check), could be spread across many different physical systems. We need to ensure that the message is being sent to the correct consumer using information contained with the message itself.

In the following example, we see the implementation of a Content-based Router pattern to route the message to the correct consumer using the Choice option that integrates the option to use a Spring bean that incorporates the conditional logic.

 

Spring Bean Example

 

<when> <method bean="myBean" method="isWidget"/> ... </when> <bean id="myBean" class="com.mycompany.MyBean"/> public boolean isWidget(@Header(name = "type") String type) { return type.equals("Widget"); }

 

NOTE: In this example, we should notice the use of Bean Parameter Binding to instruct Camel to invoke this method and pass in the type header as the String parameter. This allows your code to be fully decoupled from any Camel API so it's easy to read, write, and unit test.