camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Using a custom based load balancer.
Date Mon, 24 Sep 2012 15:20:49 GMT
Hi

In your hashmap, the session id should be the key. And the chosen
processor should be the value.

eg the type should be
Map<String, Processor> map = new ...




On Mon, Sep 24, 2012 at 4:40 PM, balkishore <balkishore.pandey@gmail.com> wrote:
> Hi claus,
>
> Thanks a lot for replying.
>
> I implemented the idea directed by you(I really appreciate that )
> But due to some reason my requests are not being forwarded, camel is
> continuously retrying.
>
> Here is my code for custom load balancer:
>
> public class MyCustomLoadBalancer extends SimpleLoadBalancerSupport
>
> {
> private final HashMap hm = new HashMap();
>
> public void process(Exchange exchange) throws Exception {
> Processor target = chooseProcessor(exchange);
> XPathBuilder sessionID =
> XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)", String.class);
> String session = sessionID.evaluate(exchange, String.class);
>
> hm.put(getProcessors(),session);
> target.process(exchange);
> }
>
> protected Processor chooseProcessor (Exchange exchange) throws Exception
> {
>         Namespaces env = new Namespaces("soapenv",
> "http://schemas.xmlsoap.org/soap/envelope/");
>         env.add("wsa", "http://www.w3.org/2005/08/addressing");
>         env.add("axis2", "http://ws.apache.org/namespaces/axis2");
>
>         Object expression = exchange.getIn().getHeader("test",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
>         if (expression.equals(hm.get(getProcessors())))
>         {
>                 return getProcessors().get(0);
>                 } else {
>                 return getProcessors().get(1);
>                 }
> }
> }
>
> And my main is something like this :
>
> from(uri).loadBalance(new MyCustomLoadBalancer()).to(BE1,BE2);
>
> where URI, BE1 and BE2 are the URLs.
>
> Am I doing something wrong in my custom load balancer method?
> I would be glad if you could help me or point out the mistake, I have done.
> I have been struggling on this project for a while now.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719861.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message