7 Replies Latest reply on Sep 19, 2012 10:12 AM by Claus Ibsen

    Problems with load balancing  in Camel.

    kishore basisth Newbie

      This would be my first post here.


      For a while now, I have been struck in this part and did a lot of research online for more than a week and couldn't end up with an answer.


      I will try to explain things from basic,

      I have web service running on backend servers that uses Axis2.

      These servers when received a request would send a response with SOAP Session ID in it.

      I would like to load balance the request among the backend servers, using the sessionID, which would be sticky.


      I have written a small route for my initial phase which is attached below.


      Now The problems i am facing are:


      1. My requests are not being distributed equally, all the requests are sent to the first server(For some reason whatsoever). SO is it possible to perform both roundrobin and sticky load balncing at the same time?

      2. When the first server is down, the requests are not automatically sent to 2nd server, the route continuously retries without even polling the second server.

      3. And my xpath expression extracts the term "ServiceGroupId" from the response, which i think it is doing because with ordinary round robin, the request were passed onto both server without stickiness.

      4. How can I display the extracted term from xpath, just to make sure it extracts the appropriate term?


      I would really appreciate if someone could help me. I didn't find any answer anywhere and without this I cannot move further in my project.


      Edited by: spaniard89 on Sep 18, 2012 11:34 AM

        • 1. Re: Problems with load balancing  in Camel.
          Claus Ibsen Master

          xpath is always causing problem for people.


          The xpath library uses their own types by default so often a xpath result is a NodeList, Node etc. But what you want is just plain text, eg a String type.


          So you need to tell the xpath expression to use String as result type


          <xpath resultType="String"> ... </xpath>


          The sticky load balancer will always pick the same one as last time, eg it does a hash of the correlation expressions which yields the same for the same expression.


          If you want failover etc. you need to build you own custom strategy.

          • 2. Re: Problems with load balancing  in Camel.
            Claus Ibsen Master

            And to see the value for the xpath, you can set it as a header value before the load balancer. Then you can see the header value when you have enabled the Camel tracer, in the logs.


            <setHeader headerName="foo">
               <xpath ...>


            • 3. Re: Problems with load balancing  in Camel.
              kishore basisth Newbie

              Thanks for replying.


              I tried tracing the request and response. But Foo is present only in my request, it is not present in my responses. Usually the first request does not contains the ServiceGroupID, the response contains it. And camel is searching for the xpath expression only in the request. How can make it search for the expression in the responses instead?


              Any help would really be appreciated.


              Edited by: spaniard89 on Sep 18, 2012 1:32 PM

              • 4. Re: Problems with load balancing  in Camel.
                Claus Ibsen Master

                Response from whom? You mean the http endpoint you load balance over?


                So what should happen on the initial call from the client? There is no session yet. In that case the correlation expression would be empty, which mean the sticky load balancer will pick (I assume the 1st one, but it depends on the hashing).


                The http endpoint would see this is a new client, and put the session id, in its response, which Camel return to the caller.


                The next time the caller calls, he must include the session id in the SOAP message, so the xpath expression can grab it.


                But the problem now is that the sticky load balancer hashing algorithm may not yield the same http server as before, because the correlation expression is different.


                You would have to write a custom load balancer or custom correlation expression to take into account the issue with the initial call so you can pick the same http server when you have the actual session id.

                • 5. Re: Problems with load balancing  in Camel.
                  Claus Ibsen Master

                  I have logged a ticket to improve this in Camel



                  It would be a good use-case to support this more easily out of the box.

                  • 6. Re: Problems with load balancing  in Camel.
                    kishore basisth Newbie

                    Hi claus,


                    First of all, thanks for logging a ticket.


                    How can I build my own custom load balancer, which would ignore the first request and would search for the expression in the response? A basic outline with function that might be useful to me, would be really beneficial. And how can I play around with requests and responses?

                    • 7. Re: Problems with load balancing  in Camel.
                      Claus Ibsen Master

                      The Camel in Action book, covers how to develop a custom load balancer, in section 8.6.4.


                      You can extend the SimpleLoadBalancerSupport class, and in choose processor method you pick the http endpoint, eg the logic to pick the same based on session id.


                      And in the process method, you will after the process(exchange) being invoked on the chose processor, do the xpath stuff.