2017-12-15 1 views
0

以下のルートでは、 "try..catch"とonexception機能の両方を使用しています。 私のbeanやtryブロック以外の行に例外がある場合は、moveFailedオプションを使用しているので、 ".error"に移動されますが、tryブロックの行によって生成されたcatchブロックによって捕捉された例外の間、ファイルは失われます。 。ファイルの取得/保存 - Apache Camelで "try .. catch"を使用しているときにcatchブロックによってキャッチされた例外がある場合

1.when server is down 
    2.when connection timeout 

ような失敗/例外

<camelContext streamCache="false" useMDCLogging="true" id="XXX" xmlns="http://camel.apache.org/schema/spring"> 
    <streamCaching spoolDirectory="/tmp/cachedir/#camelId#/#uuid#" spoolUsedHeapMemoryThreshold="70" bufferSize="65536" anySpoolRules="true" id="myCacheConfig"/> 
    <onException > 
     <description>An exception was encountered.</description> 
     <exception>java.lang.Exception</exception> 
     <log message="somemessage" loggingLevel="INFO"/> 
    </onException> 
<route >   
    <from uri="file:D:/Users/Desktop/src?moveFailed=.error" /> 
    <transform> 
     <method ref="somebean" method="somemethod"/> 
    </transform> 
    <doTry> 
     <to uri="file:D:/Users/Desktop/src" /> 
     <log message="transfered successfully" />   
     <doCatch> 
      <exception>java.lang.Exception</exception> 
       <log message="Exception occurred and Stopping the Route"/> 
       <to uri="controlbus:route?routeId=XXXX&amp;action=stop"/>      
       <log message="Stopped the Route:XXX"/> 
     </doCatch> 
    </doTry> 
</route> 

中にファイルを保存するための方法を提案してくださいそのような失敗/例外中にファイルを保存するための方法を提案してください

答えて

0

例外再スローI nあなたのdocatch-blockをonExceptionブロックに到達させます。

 <doCatch> 
     <exception>java.lang.Exception</exception> 
      <log message="Exception occurred and Stopping the Route"/> 
      <to uri="controlbus:route?routeId=XXXX&amp;action=stop&amp;async=true"/> // async=true to resume/finish this route      
      <log message="Stopped the Route:XXX"/> 
      <throwException exception="java.lang.Exception"/> // dont know the exact syntax in xml dsl 
    </doCatch> 
+0

例外を再スローすると、いつルートを停止する必要がありますか? 私のシナリオをキャッチのルートを停止することを考慮してください。また、同じプロトタイプ/構造を提供してください。 –

+0

コントロールバスのasyncパラメータを使用できます。機内交換でラムを停止すると、ラクダは自動的に優雅なシャットダウン機能を使用し、ルートを「殺す」まで待機します(デフォルトは300秒)。 – soilworker

関連する問題