2016-12-06 58 views
0

我使用apache camel xml dsl在路由上創建。 而我想用errorHandlerRef處理異常。但是這隻能用於路由標記。 這裏是我的路由上下文:我該如何處理Apache Camel的管道級別的execption?

<routeContext id="myRoute" xmlns="http://camel.apache.org/schema/spring"> 
    <route errorHandlerRef="myErrorHandler" id="myErrorRoute"> 
     <from uri="activemq:queue:{{my.queue}}" /> 
     <multicast> 
      <pipeline> 
     //setting headers and other properties 
       <to uri="spring-redis://localhost:6379?serializer=#stringSerializer" /> 
      </pipeline> 
      <pipeline> 
     //want to put error handling here 
     <log message="Insert to DB" /> 
     <to uri="mybatis:insertToDB?statementType=InsertList"></to> 
      </pipeline> 
     </multicast> 
    </route> 
</routeContext> 

有沒有什麼辦法可以處理流水線級的異常。 例如,在這裏我想爲這兩個管道創建不同的錯誤處理程序。我怎樣才能做到這一點? 我試着把errorHanlerRef和管道標籤放在一起,但是那裏有編譯錯誤。

回答

0

如駱駝2.0的,它可以使用本doTry,doCatch和doFinally這裏描述http://camel.apache.org/try-catch-finally.html和可被實現爲如下完成:

<doTry> 
    <to uri="mybatis:insertToDB?statementType=InsertList"></to> 
    <doCatch> 
     <exception>java.io.IOException</exception> 
     <to uri="mock:catch"/> 
     <log message="Exception message : ${exception.message}" 
      loggingLevel="ERROR" /> 
    </doCatch> 
    <doFinally> 
     <to uri="mock:finally"/> 
    </doFinally> 
</doTry>