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: Calling dynamically multiple http endpoints
Date Thu, 14 May 2009 16:19:26 GMT
On Thu, May 14, 2009 at 4:55 PM, Nasim Anza <nasmo2009@googlemail.com> wrote:
> Thanks Claus for your quick answer.
>
> I downloaded the source of camel 2.0 and I looked at the
> FailOverLoadBalancer class. I think that this could answer to my question.
> I've tried to adapt the code to my requirement but I have some questions
> about the list of processors used in this class :
>
> 1. I don't know How to create or initialize the processors used for
> balancing user requests ?
>
> 2. Shall I create a camel Processor for each HTTP URL ?
>
> 3. Whait is the syntaxe (maybe something like new Processor(myHttpURL))
Hi

Yeah there is no nice DSL support for it and the loadbalance() DSL
does not have a nice support for custom load balancer.
So that is something we might need to improve in the future. I have to
remember this thread.

So what you basically have to do is to add your custom load balancer
as a processor, so use the process() DSL.

And your custom fail over loadbalancer can accept a list of endpoints
to select among. You can wrap an endpoint to a processor
with the SendToProcessor.

Something like this

MyFailover my = new MyFailoverProcessor()l;
my.addEndpoint("foo");
my.addEndpoint("bar");


And in the route DSL you just route to your processor
from(x).process(my);

And in the addEndpoint method you add the endpoint by wrapping it with
a SendToProcessor so you can add it to the LoadBalancerSupport class.

See how it goes and ask again tomorrow when I am back in the office
and can better work. As I sit now with the laptop in the living room.


>
> Thanks for help
>
>
>
>
> On Thu, May 14, 2009 at 11:59 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
>
>> Hi
>>
>> There are load balancers with Camel
>> http://camel.apache.org/load-balancer.html
>>
>> And there is a failover load balancer as well that can do a simple  try
>> the next endpoint until success kinda style.
>> Its a bit primitive at the moment and we would like to improve that in
>> the future.
>>
>> But it allows you to implement your own load balancer and do your
>> strategy how you like it.
>>
>> Any feedback for features that could be needed for a more advanced
>> failover loadbalancer is much welcome.
>>
>> Ah the failover loadbalancer is not part of Camel 1.x. But you can
>> check the source code for 2.0 and create your own kinda to use in 1.x.
>>
>> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/
>>
>>
>>
>> On Thu, May 14, 2009 at 11:45 AM, Nasim Anza <nasmo2009@googlemail.com>
>> wrote:
>> > Hi,
>> >
>> > I would like to implement the following route with Camel 1.6 :
>> >
>> > from("direct:endpointA")
>> > .setHeader(HttpProducer.HTTP_URI).simple("http://myAddressA")
>> > .to("http://xxxxxx")
>> > .to("direct:endPointB")
>> >
>> > from("direct:endpointB")
>> > .setHeader(HttpProducer.HTTP_URI).simple("http://myAddressB")
>> > .to("http://xxxxxx")
>> > .to("direct:endPointC")
>> >
>> > from("direct:endPointC")
>> > .to("xquery:response.xml");
>> >
>> > This route works fine if both URLs : http://myAddressA and
>> > http://myAddressBare accessible and no error occurs during the
>> > invocation.
>> > Unfortunately, sometimes these services become unreachable and I would
>> like
>> > to try other URLs until getting valid answer:
>> >
>> > If an exception happens when calling the URL http:/:myAddressA, I would
>> like
>> > to attempt other URLs : myAddressA1, myAddressA2, ...until getting valid
>> > HTTP response.
>> > The same thing with myAddressB ==> myAddressB1, myAddressB2, ...
>> >
>> > With java this could be simply coded like following :
>> >
>> > try
>> > {
>> >  call_http(myAddressA)
>> > }
>> > catch(Throwable th)
>> > {
>> >     try
>> >      {
>> >        call_http(myAddressA1)
>> >      }
>> >      catch(Exception x)
>> >      {
>> >           //Call addressA2
>> >           ....
>> >      }
>> > }
>> >
>> > I've tried the onException() mechanism and the deadLetterChannel
>> processor
>> > but I never get working my route.
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message