camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bocamel <johnz...@gmail.com>
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.

 

Thanks! 

 

 

From: Ranx [via Camel] [mailto:ml-node+s465427n5781523h91@n5.nabble.com] 
Sent: Thursday, April 21, 2016 11:53 PM
To: bocamel <johnzyin@gmail.com>
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. 
   nextProcessor.process(exchange); 
  } 
} 

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

etc. 

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



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
such 
> 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
to 
> 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: 
>
http://camel.465427.n5.nabble.com/How-to-return-early-from-a-direct-subroute
-tp5780262p5781499.html
> Sent from the Camel - Users mailing list archive at Nabble.com. 
> 

 

  _____  

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

http://camel.465427.n5.nabble.com/How-to-return-early-from-a-direct-subroute
-tp5780262p5781523.html 

To unsubscribe from How to return early from a direct: subroute?, click here
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscrib
e_by_code&node=5780262&code=am9obnp5aW5AZ21haWwuY29tfDU3ODAyNjJ8Mjk3Mjc3MTQ4
> .
 
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_view
er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNa
mespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.No
deNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_ema
ils%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-return-early-from-a-direct-subroute-tp5780262p5781560.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message