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 <[email protected]> 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.
>