PDA

View Full Version : Difference between Router and If condition?



srikanthradix
Mar 1st, 2010, 12:52 PM
Why can't I use a simple If condition instead of routers? What is the difference? Ofcourse, a router is also simple but why/when a router is required?



<si:router input-channel="postProcessing" ref="postProcessingRouter" method="route"/>

<bean id="postProcessingRouter" class="com.xx.MessageRouter">
<property name="destinations">
<map>
<entry key="PREVALIDATED" value="prevalidation"/>
</map>
</property>
<property name="defaultDestination" value="toSplit"/>
</bean>

Mark Fisher
Mar 1st, 2010, 12:57 PM
Would a <header-value-router/> do the job?

oleg.zhurakousky
Mar 1st, 2010, 04:10 PM
Routers are based on conditions, so naturally they are implemented via 'if' and 'switch case" constructs. But there is a difference between using an 'if' statement in your business logic when you trying to process message differently based on the data in the message vs routing message to a different channel (thus different process) based on some pre-condition.
Think of it as separation of concerns between Integration logic (routers) and Business logic (generic 'if' construct)