Quantcast

Load balancing-camel in real world

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Load balancing-camel in real world

balkishore
Dear memebers,
This would be my first post in this forum and I am glad. I have started using camel a while back for a project of mine to create a load balancing application.

Well to start with,
My load balncer would listen to a port, lets say 8080 and would balance all the incoming SOAP requests to a set of backened servers.
These backend servers have apache tomcat installed and listen to port 8080. The load balancer would be recieving the request from a web browser.
I would have configured the clients in such a way that they would send the request directly to load balancer.

Now I have written a small route for initial phase, which is as follow:


public class LoadBalancer {
   public static void main(String args[]) throws Exception {
          CamelContext context = new DefaultCamelContext();

        context.addRoutes(new RouteBuilder() {

            public void configure() {
            from("jetty://http://localhost:8080")
                .loadBalance().roundRobin().to("http://172.28.39.138:8080","http://172.168.20.118:8080");
            }
        });
       
        context.start();

        Thread.sleep(100000);  
        context.stop();
    }
 }
 
 As it can be seen, i am forwarding all the request to two ip address.
 When I run this code, I don't get any error, but my client browser shows an error which explicitly means that the request was not recieved by the load balancer server.
And when I type localhost:8080, on the local computer where the camel is running, I get

HTTP ERROR: 404
Problem accessing /. Reason:

    Not Found

I have no idea, why the requests are not being recieved by the camel and why am i getting this error in the browser.

Any help would be very much appreciated. I even tried to log the incoming request using this piece of code
from("jetty://http://localhost:8080")
            .to("file:output");
            from("file://output").process(new Processor() {
               
            private Exchange e;
               
                                        public void process(Exchange exchange) throws Exception {
                   System.out.println("Received exchange:" + e.getIn());
              }
            });
                               
But it seems my camel isn't recieveing any request at all and i get nothing.

Any help would be really useful as I am struck in this phase for a long time.

Cheers!
                       
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

Christian Mueller
It's good practice to use 0.0.0.0 instead of localhost if you want to
listen on all network interfaces.

Best,
Christian

Sent from a mobile device
Am 15.08.2012 14:15 schrieb "balkishore" <[hidden email]>:

> Dear memebers,
> This would be my first post in this forum and I am glad. I have started
> using camel a while back for a project of mine to create a load balancing
> application.
>
> Well to start with,
> My load balncer would listen to a port, lets say 8080 and would balance all
> the incoming SOAP requests to a set of backened servers.
> These backend servers have apache tomcat installed and listen to port 8080.
> The load balancer would be recieving the request from a web browser.
> I would have configured the clients in such a way that they would send the
> request directly to load balancer.
>
> Now I have written a small route for initial phase, which is as follow:
>
>
> public class LoadBalancer {
>    public static void main(String args[]) throws Exception {
>           CamelContext context = new DefaultCamelContext();
>
>         context.addRoutes(new RouteBuilder() {
>
>             public void configure() {
>                 from("jetty://http://localhost:8080")
>
> .loadBalance().roundRobin().to("http://172.28.39.138:8080","
> http://172.168.20.118:8080");
>             }
>         });
>
>         context.start();
>
>         Thread.sleep(100000);
>         context.stop();
>     }
>  }
>
>  As it can be seen, i am forwarding all the request to two ip address.
>  When I run this code, I don't get any error, but my client browser shows
> an
> error which explicitly means that the request was not recieved by the load
> balancer server.
> And when I type localhost:8080, on the local computer where the camel is
> running, I get
>
> HTTP ERROR: 404
> Problem accessing /. Reason:
>
>     Not Found
>
> I have no idea, why the requests are not being recieved by the camel and
> why
> am i getting this error in the browser.
>
> Any help would be very much appreciated. I even tried to log the incoming
> request using this piece of code
> from("jetty://http://localhost:8080")
>                 .to("file:output");
>                 from("file://output").process(new Processor() {
>
>                         private Exchange e;
>
>                                         public void process(Exchange
> exchange) throws Exception {
>                         System.out.println("Received exchange:" +
> e.getIn());
>                    }
>                 });
>
> But it seems my camel isn't recieveing any request at all and i get
> nothing.
>
> Any help would be really useful as I am struck in this phase for a long
> time.
>
> Cheers!
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Load-balancing-camel-in-real-world-tp5717381.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

balkishore
Thanks for replying. But I even tried using 0.0.0.0. Still my problem is not resolved.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

Claus Ibsen-2
On Wed, Aug 15, 2012 at 2:44 PM, balkishore <[hidden email]> wrote:
> Thanks for replying. But I even tried using 0.0.0.0. Still my problem is not
> resolved.
>

Are you sure the SOAP services on those remote server is exposed at
the root, eg this url?
http://172.28.39.138:8080/

For example if you type that in a web browser do you see a response?


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-balancing-camel-in-real-world-tp5717381p5717383.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

Willem.Jiang
In reply to this post by balkishore
Current jetty component have some trouble to setup right context path if you don't specify it like this
from("jetty://http://localhost:8080")
You can change the uri like this
from("jetty://http://localhost:8080/")

if you want to implement a proxy you need to setup the route like this
from("jetty://http://localhost:8080/?matchOnUriPrefix=true").loadBalance().roundRobin().to("http://172.28.39.138:8080?throwExceptionOnFailure=false&bridgeEndpoint=true","http://172.168.20.118:8080?throwExceptionOnFailure=false&bridgeEndpoint=true");


--
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang



On Wednesday, August 15, 2012 at 8:10 PM, balkishore wrote:

> Dear memebers,
> This would be my first post in this forum and I am glad. I have started
> using camel a while back for a project of mine to create a load balancing
> application.
>
> Well to start with,
> My load balncer would listen to a port, lets say 8080 and would balance all
> the incoming SOAP requests to a set of backened servers.
> These backend servers have apache tomcat installed and listen to port 8080.
> The load balancer would be recieving the request from a web browser.
> I would have configured the clients in such a way that they would send the
> request directly to load balancer.
>
> Now I have written a small route for initial phase, which is as follow:
>
>
> public class LoadBalancer {
> public static void main(String args[]) throws Exception {
> CamelContext context = new DefaultCamelContext();
>
> context.addRoutes(new RouteBuilder() {
>
> public void configure() {
> from("jetty://http://localhost:8080")
>
> .loadBalance().roundRobin().to("http://172.28.39.138:8080","http://172.168.20.118:8080");
> }
> });
>
> context.start();
>
> Thread.sleep(100000);
> context.stop();
> }
> }
>
> As it can be seen, i am forwarding all the request to two ip address.
> When I run this code, I don't get any error, but my client browser shows an
> error which explicitly means that the request was not recieved by the load
> balancer server.
> And when I type localhost:8080, on the local computer where the camel is
> running, I get
>
> HTTP ERROR: 404
> Problem accessing /. Reason:
>
> Not Found
>
> I have no idea, why the requests are not being recieved by the camel and why
> am i getting this error in the browser.
>
> Any help would be very much appreciated. I even tried to log the incoming
> request using this piece of code
> from("jetty://http://localhost:8080")
> .to("file:output");
> from("file://output").process(new Processor() {
>
> private Exchange e;
>
> public void process(Exchange exchange) throws Exception {
> System.out.println("Received exchange:" + e.getIn());
> }
> });
>
> But it seems my camel isn't recieveing any request at all and i get nothing.
>
> Any help would be really useful as I am struck in this phase for a long
> time.
>
> Cheers!
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-balancing-camel-in-real-world-tp5717381.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

balkishore
In reply to this post by Claus Ibsen-2
Thanks for replying. Yeah when I input http://172.28.39.138:8080/ in my browser, apache tomcat page opens. As it is a backend server, and it runs tomcat in it which is listening on the port 8080 for requests.

I am still struck in this part. Am I doing something wrong?
Any help would be very much appreciated. And again thanks a ton for replying.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

balkishore
In reply to this post by Willem.Jiang
Thanks for replying. I changed from("jetty://http://localhost:8080/")  in my code, and still i get the same error, when i send a request. But when i type http://localhost:8080/ on my browser, i get an error like this:

java.lang.IllegalArgumentException: Invalid uri: /. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: Endpoint[http://172.28.39.138:8080]


        at org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:357)
        at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:89)
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:120)
        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:292)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:115)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:330)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
        at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.loadbalancer.QueueLoadBalancer.process(QueueLoadBalancer.java:44)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at java.lang.Thread.run(Thread.java:662)
And many others.

I have no idea what's wrong here?
Any help would be really appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

Willem.Jiang
Did you have chance to enable the bridgeEndpoint option as I showed ?


--
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang



On Wednesday, August 15, 2012 at 9:35 PM, balkishore wrote:

> Thanks for replying. I changed from("jetty://http://localhost:8080/") in my
> code, and still i get the same error, when i send a request. But when i type
> http://localhost:8080/ on my browser, i get an error like this:
>
> java.lang.IllegalArgumentException: Invalid uri: /. If you are
> forwarding/bridging http endpoints, then enable the bridgeEndpoint option on
> the endpoint: Endpoint[http://172.28.39.138:8080]
>
>
> at
> org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:357)
> at
> org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:89)
> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:120)
> at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:292)
> at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:115)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:330)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
> at
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.loadbalancer.QueueLoadBalancer.process(QueueLoadBalancer.java:44)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at java.lang.Thread.run(Thread.java:662)
> And many others.
>
> I have no idea what's wrong here?
> Any help would be really appreciated.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-balancing-camel-in-real-world-tp5717381p5717391.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

balkishore
Yes I tried! But still it didn't work. I am getting this error with the bridgeEndpoint added in the code.
Any help would be very much appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Load balancing-camel in real world

balkishore
I figured it out. Instead of localhost or 0.0.0.0 in the from if I directly insert the IP address of the local host and remove / after the port number in URI, everything works fine. :)

So the code would would be something like this
from("jetty://http://192.168.39.204:8080?matchOnUriPrefix=true")

Hope it helps!
Loading...