You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mnl <mn...@gmail.com> on 2016/02/10 05:27:45 UTC

Switch to route in case original route fails

I have 2 routes of which one acts as the main route and other one is required
in case original fails. Now, there are 2 kinds of requirements:
1. If original (say route1) fails, I switch to other route (say route2) and
start sending exchange using route2. But in background I check if route1 can
be active again. If this happens I want to use route1 again instead of
route2. So in this way route2 is required only at times route1 is not
functional.

2. If route1 fails, we start using route2. But in times when route2 fails, I
want to check route1 and start using it again. So here we alternate between
route1 and route2 depending which is available and working.

I read through the camel documentation and I came across OnCompletion
concept (http://camel.apache.org/oncompletion.html) which can help me switch
to different route in case original fails. But I am not able to accomplish
either of above tasks successfully with this.
I want to switch to original route again or alternate between them depending
on their availability. Does camel already provide this functionality? If
yes, please refer me some documentation, else please direct me the steps
which I can follow?

Any help in this matter is appreciated. Thanks :)




--
View this message in context: http://camel.465427.n5.nabble.com/Switch-to-route-in-case-original-route-fails-tp5777511.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by mnl <mn...@gmail.com>.
I checked the load balancer documentation for apache. It looks pretty good
for my use case. However I have few queries for which I couldn't find
answers in the documentation:

1. In my understanding, for apache to failover and use other routes, all the
routes should be active. Am I correct? or is it so that the route becomes
active i.e. the connection is made only when there is need for that route?

2. Suppose I have 2 routes (say, A and B) added in the list. I want to try
A, if it fails, then B. Then if B fails I want to wait for (let say ) 3s and
then again start with A continuing to B (if A fails) and so on. So, after
trying all the routes I want to wait for some time before it resumes to try
again all the connections from beginning. Is it possible to implement this
strategy with currently available configurations?

Looking forward to reply.
Thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/Switch-to-route-in-case-original-route-fails-tp5777511p5778147.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by mnl <mn...@gmail.com>.
Thanks !!

Can someone please point me to the implementation of failover load balancer.
All I could see is this
https://github.com/apache/camel/blob/cc9924f41965885af25027fc053adaf21f15b5b4/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java

but it no where uses inheritErrorHandler attribute  as mentioned on
http://camel.apache.org/load-balancer.html for failover loadBalancer.



--
View this message in context: http://camel.465427.n5.nabble.com/Switch-to-route-in-case-original-route-fails-tp5777511p5778316.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by Sashika <sa...@gmail.com>.
The easiest way is to set it in a header like .setHeader(“NODE”,constant(“A”) )
when processing in each A or B. Get the header value when you want to find out
which node processed the message.



On Wed, Feb 24, 2016 at 1:30 PM, mnl < mnlgoyal17@gmail.com > wrote:
One more thing:

Let's say I have C endpoint which will send to B and might failover to A in
case of exception on B. Now I want to know whether it was A or B which
successfully completed the request. How can I know that? This is required to
process the message which A or B might send back to C.



--
View this message in context: http://camel.465427.n5.nabble. com/Switch-to-route-in-case-
original-route-fails- tp5777511p5778162.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by mnl <mn...@gmail.com>.
One more thing:

Let's say I have C endpoint which will send to B and might failover to A in
case of exception on B. Now I want to know whether it was A or B which
successfully completed the request. How can I know that? This is required to
process the message which A or B might send back to C. 



--
View this message in context: http://camel.465427.n5.nabble.com/Switch-to-route-in-case-original-route-fails-tp5777511p5778162.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by mnl <mn...@gmail.com>.
Hi Sashika,

Thanks for the reference. It was helpful. 



--
View this message in context: http://camel.465427.n5.nabble.com/Switch-to-route-in-case-original-route-fails-tp5777511p5777521.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Switch to route in case original route fails

Posted by Sashika <sa...@gmail.com>.
This might help you Apache Camel: Load Balancer This option can be used whether or not roundRobin is enabled or not.Camel 2.3:
Whether or not the failover load balancer should operate in round… camel.apache.org

On Wed, Feb 10, 2016 at 9:57 AM, mnl < mnlgoyal17@gmail.com > wrote:
I have 2 routes of which one acts as the main route and other one is required
in case original fails. Now, there are 2 kinds of requirements:
1. If original (say route1) fails, I switch to other route (say route2) and
start sending exchange using route2. But in background I check if route1 can
be active again. If this happens I want to use route1 again instead of
route2. So in this way route2 is required only at times route1 is not
functional.

2. If route1 fails, we start using route2. But in times when route2 fails, I
want to check route1 and start using it again. So here we alternate between
route1 and route2 depending which is available and working.

I read through the camel documentation and I came across OnCompletion
concept ( http://camel.apache.org/ oncompletion.html ) which can help me switch
to different route in case original fails. But I am not able to accomplish
either of above tasks successfully with this.
I want to switch to original route again or alternate between them depending
on their availability. Does camel already provide this functionality? If
yes, please refer me some documentation, else please direct me the steps
which I can follow?

Any help in this matter is appreciated. Thanks :)




--
View this message in context: http://camel.465427.n5.nabble. com/Switch-to-route-in-case-
original-route-fails- tp5777511.html
Sent from the Camel - Users mailing list archive at Nabble.com.