On Mon, Sep 24, 2012 at 11:59 AM, balkishore
<balkishore.pan...@gmail.com> wrote:
> Hi,
> I want to perform a sticky based load balancing based on the SOAP session ID
> in the response.
> As camel's loadbalance.sticky() just check for the expression in the
> request, I have to implement my own custom load balancer.
>
> I gave a look at camel in action book and the information provided in the
> section 8.6.4(Custom load balancer section) are two less.
>
> With the help of the developer(Claus) in the fuse source forum, I decided to
> plug in my own custom load balancer.
>
> The Problems I am facing now are:
>
> 1. There are two methods in custom based load balancer: Process and other is
> choosing a processor: I know I have to plugin my own logic in the choosing
> processor method. But how would my logic look like? I want to extract the
> session id from the response(Just the response), and match this session id
> with the second request I get from the client(If they are same i would
> forward the request to same processor).
>
> 2.In order to get the session from the response I came up with something
> like this:
>
> String expression = (String) exchange.getOut().getHeader("ServiceGroupId",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
> If i am not wrong it would pick the session id from the response. (Now where
> should I add this code?) In the process method or choose processor method?
>

Your custom load balancer would need to keep state, so you can map the
initial request with the session id you get from the response
afterwards. So eg you need to store the session id in a map, so you
can pick the same processor the next time.

So pseudo logic would be

In the choose process method

1) try to get the session id from the soap header (would not be there
on the initial call)
2) if you got a session id, lookup in your map to find the processor to choose
3) if there is no session id (= initial call) then pick for example a
random processor, as you need to pick one

In the process method
4) after call the process method on the chosen processor, do the xpath
to get the session id (the code you have above)
5) store the session id -> processor (to remember the chosen processor)

Now you would need to use a timeout based map etc to have the map
cleanup itself when the client goes away. Camel has a timeout based
map you can use. Otherwise your map will keep a reference to the old
sessions forever.






> 3. If I add this code in my choose processor method, how would my process
> method look like?
>
> I would really appreciate if anyone could give me an outline "On how to join
> the dots in camel".
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841.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: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to