2016-12-06 61 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>