hi - I found a solution for this issue:
I created a processor which adds a header field "queueid" and the value of
sessionid % x
Code of the processor:
*************************************************
public class HeaderProcessor<T extends AbstractBase> implements Processor,
ParamDefinitions {
private int numberOfConsumers;
public void process(Exchange exchange) throws Exception {
ObjectImpressionTransportBean transportBean =
(ObjectImpressionTransportBean)(exchange.getIn().getBody());
String sessionid =
transportBean.getSensorCall().getParameter().get(PARAMETERKEY_SESSIONID);
if (sessionid != null) {
int queueid = sessionid.hashCode()%numberOfConsumers;
exchange.getOut().setHeader("queueid",
Integer.toString(queueid));
} else {
exchange.getOut().setHeader("queueid", "0");
}
}
public int getNumberOfConsumers() {
return numberOfConsumers;
}
public void setNumberOfConsumers(int numberOfConsumers) {
this.numberOfConsumers = numberOfConsumers;
}
}
*************************************************
then I use the "choice" tag to redirect the messages:
Code of the route:
*************************************************
<endpoint id="input1"
uri="${jms.bean}:${jms.OIConveyerQueue}?concurrentConsumers=${jms.concurrentConsumers}"/>
<endpoint id="output1" uri="${jms.bean}:${jms.SessionManagerQueue1}"/>
<endpoint id="output2" uri="${jms.bean}:${jms.SessionManagerQueue2}"/>
<endpoint id="output3" uri="${jms.bean}:${jms.SessionManagerQueue3}"/>
<route>
<from ref="input1" />
<to uri="queueSwitchProcessor" />
<!-- <to uri="gateOut" />-->
<choice>
<when>
<xpath>$queueid = "0"</xpath>
<to ref="output1"/>
</when>
<when>
<xpath>$queueid = "1"</xpath>
<to ref="output2"/>
</when>
<otherwise>
<to ref="output3"/>
</otherwise>
</choice>
</route>
.......
<bean id="queueSwitchProcessor"
class="com.fatwire.analytics.camel.processor.HeaderProcessor">
<property name="numberOfConsumers" value="3"/> <!-- number of
consumers
-->
</bean>
*************************************************
--
View this message in context:
http://www.nabble.com/How-to-route-a-message-based-on-a-criteria---tp18506590s22882p18511610.html
Sent from the Camel - Users mailing list archive at Nabble.com.