如何将错误重定向到Apache Camel中的路由

问题描述:

我的骆驼上下文示例。如何将错误重定向到Apache Camel中的路由

<camel:camelContext> 
    <camel:route id="r1"> 
     <camel:from="someEndpoint"/> 
     ... 
     <camel:to="to2"/> 
    </camel:route> 
    <camel:route id="r2"> 
     <camel:from="to2"/> 
     ... 
     <camel:to="to3"/> 
    </camel:route> 
    <camel:route id="r3"> 
     <camel:from="to3"/> 
     ... 
     <camel:to="to4"/> 
    </camel:route> 
    <camel:route id="r4"> 
     <camel:from="to4"/> 
     ... 
     <camel:to="exit"/> 
    </camel:route> 

    <camel:route id="errorProcessorRoute"> 
     <camel:from="???"/> 
     ...Some action... 
     <camel:to="exit"/> 
    </camel:route> 
</camel:camelContext> 

我需要,如果有任何错误发生比procces路由 - > errorProcessorRoute。

如何实现它?

如果你想赶上你可以使用onException的标签

<camel:camelContext> 
    .... 

    <camel:route id="errorProcessorRoute"> 
     <camel:from="direct:foo"/> 
     ...Some action... 
     <camel:to="exit"/> 
    </camel:route> 

    <onException> 
     <exception>java.lang.Exception</exception> 
     <to uri="direct:foo"/> 
    </onException> 

</camel:camelContext> 

<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead"> 
    <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000" logHandled="true" asyncDelayedRedelivery="true"/> 
</camel:errorHandler> 

here

+0

任何错误,以及如何将重定向到“errorProcessorRoute”路线? – nkukhar 2012-02-09 14:49:22

+1

你需要在上配置errorHandlerRef来告诉它应该使用该错误处理程序的路由 – 2012-02-09 14:57:48

+0

你能告诉我一些例子吗?我的想法是添加全局错误处理程序,如果在任何路径中发生错误,则将其解析为路由(id =“errorProcessorRoute”),并执行一些步骤(对于所有错误都是相同的)以对其进行排序。可能吗? – nkukhar 2012-02-09 22:27:49