2012-02-09 140 views
1

我的駱駝上下文示例。如何將錯誤重定向到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。

如何實現它?

回答

1

如果你想趕上你可以使用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> 
1
<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

相關問題