camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bocamel <>
Subject RE: How to return early from a direct: subroute?
Date Fri, 22 Apr 2016 13:29:04 GMT
Hi Ranx,


After giving it more thoughts, I think your suggestion of throwing exception
is a neat solution.  Using a route level OnException to catch and handle the
exception, then quietly return to the caller of the direct route.  I will
give it a try.  


But there are situations where I need to disable error-handling at route
level - for example, to force the retry to start in the parent route.  So
the throwing exception approach might not work for those situations.  Thanks
for the example on processor chain.  I will play with it.





From: Ranx [via Camel] [] 
Sent: Thursday, April 21, 2016 11:53 PM
To: bocamel <>
Subject: Re: How to return early from a direct: subroute?


Is there a reason you don't want to throw an exception?  If you have 
multiple processors in a row like that all of which might throw exceptions 
that certainly seems reasonable.  The other possibility here is to inject 
your processors into one another in a chain of responsibility.  I usually 
use a chain of Pojos if I need that but it would be similar.  Don't copy 
this as I'm writing it in plain text after a long day flying and it's not 
coming out of an IDE.  Plus I never use Processors/Exchanges and use 
blueprint so don't know if the XML would match what you're after.  But you 
get the idea. 

public class MyProcessor implements Processor { 
  Processor nextProcessor; 
  //put in getters/setters 
  public void process(Exchange exchange) throws Exception { 
    // do something... 
   //if logic is correct then call next processor otherwise return. 

<bean id="processorChain" class="my.first.Processor"> 
   <property name="nextProcessor" ref="secondProcessor"/> 


  <from uri="direct:in"> 
  <bean ref="processorChain"/> 

On Thu, Apr 21, 2016 at 2:09 PM, bocamel <[hidden email]> wrote: 

> Thank you all very much for responding to my question and for offering 
> solutions.  I have implemented my application using a combination of 
> headers 
> and <choice>.  But I also concluded that there is not a simple and elegant

> way to do what I intended to do.  I wish the great Camel team will add
> a feature in a future release. 
> <feature request> 
> Add a new property header in Exchange:  ROUTE_RETURN 
> When processing an exchange in a direct route, if this property is true, 
> then Camel will stop propagating this exchange through the rest of the 
> direct route and return the exchange back to the caller of the direct 
> route. 
> It is the responsibility of the user who sets this property to set the 
> camel 
> message body/headers so that the caller of the direct route can continue
> process it. 
> The exception/error handling can stay the same, i.e. they do not need to 
> check this property. 
> </feature request> 
> -- 
> View this message in context: 
> Sent from the Camel - Users mailing list archive at 



If you reply to this email, your message will be added to the discussion

To unsubscribe from How to return early from a direct: subroute?, click here
> .
ils%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 

View this message in context:
Sent from the Camel - Users mailing list archive at
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message