Mule ESB:如何通过MEL处理Mule批处理中的异常

时间:2014-09-14 01:13:14

标签: mule mule-studio mule-el mule-component

我第一次在mule中使用批处理,不知道如何处理批处理记录的异常。

记录输入阶段失败,但无法在输入阶段记录器和批处理步骤(故障流程)记录器中捕获故障异常。也许MEL #[inputPhaseException] 本身会抛出异常。

<batch:job name="Batch1" max-failed-records="-1">
    <batch:threading-profile poolExhaustedAction="WAIT"/>
    <batch:input>
        <file:inbound-endpoint path="C:\IN" responseTimeout="10000" doc:name="File"/>
 <component class="com.General" doc:name="Java"/>
        <logger message="InputPhase: #[inputPhaseException]" level="INFO" doc:name="Logger"/>
    </batch:input>
    <batch:process-records>
        <batch:step name="Batch_Step"  accept-policy="ALL" ">
            <data-mapper:transform config-ref="Pojo_To_CSV" doc:name="Pojo To CSV"/>               
            <file:outbound-endpoint path="C:\Users\OUT" outputPattern="#[function:dateStamp]_product.csv" responseTimeout="10000" doc:name="File"/>
        </batch:step>
        <batch:step name="FailureFlow" accept-policy="ONLY_FAILURES">
            <logger message="Inside Failure: #[getStepExceptions()], Loading Phase: #[failureExceptionForStep],#[inputPhaseException] " level="ERROR" doc:name="Logger"/>
        </batch:step>
    </batch:process-records>
    <batch:on-complete>
        <logger level="INFO" doc:name="Logger" message=" On Complete: #[payload.loadedRecords] Loaded Records #[payload.failedRecords] Failed Records"/>
    </batch:on-complete>
</batch:job>

批处理MEL是否有任何限制仅用于输入阶段和过程记录和完成时的某些MEL。因为我尝试在Failure流程中保留大部分get..Exception {},所以它会抛出错误。 请提前建议,谢谢。

2 个答案:

答案 0 :(得分:1)

是的..你是对的.. #[inputPhaseException]造成所有问题.. 我修改了你的骡流,你可以尝试以下方法: -

<batch:job name="Batch1" max-failed-records="-1">
    <batch:threading-profile poolExhaustedAction="WAIT"/>
    <batch:input>
   <file:inbound-endpoint path="C:\IN" responseTimeout="10000" doc:name="File"/>
    <component class="com.General" doc:name="Java"/>
   </batch:input>
 <batch:process-records>
 <batch:step name="Batch_Step"  accept-policy="ALL" ">
   <data-mapper:transform config-ref="Pojo_To_CSV" doc:name="Pojo To CSV"/>               
  <file:outbound-endpoint path="C:\Users\OUT" outputPattern="#[function:dateStamp]_product.csv" responseTimeout="10000" doc:name="File"/>
 </batch:step>

<batch:step name="Batch_Failed">
<logger doc:name="Logger" level="ERROR" message="Record with the following payload has failed. Payload:: #[message.payload], Loading Phase: #[failureExceptionForStep], Inside Failure the exception is :- #[getStepExceptions()]" />
  </batch:step>
</batch:process-records>
  <batch:on-complete>
    <logger message="Number of failed Records: #[payload.failedRecords] " level="INFO" doc:name="Failed Records" />
    <logger level="INFO" doc:name="Logger" message=" Number of loadedRecord: #[payload.loadedRecords]"/>
    <logger message="Number of sucessfull Records: #[payload.successfulRecords]"    level="INFO" doc:name="Sucessfull Records" />
    <logger message="ElapsedTime #[payload.getElapsedTimeInMillis()]" level="INFO" doc:name="Elapsed Time" />
   </batch:on-complete>
 </batch:job>

答案 1 :(得分:1)

是的,你需要在The On complete Phase中使用它最终阻止收集成功和不成功的批量结果。 https://dzone.com/articles/handle-errors-your-batch-job%E2%80%A6