【问题标题】:Mule ESB: How to handle Exception in Mule Batch through MELMule ESB:如何通过 MEL 处理 Mule Batch 中的异常
【发布时间】:2014-11-07 20:51:16
【问题描述】:

我是第一次在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。因为我尝试将大部分 get..Exception{} 保留在失败流中,所以它会抛出错误。 请建议,提前谢谢。

【问题讨论】:

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


    【解决方案1】:

    是的 .. 你是对的 .. #[inputPhaseException] 导致了所有问题 .. 我已经修改了您的 Mule 流程,您可以尝试以下操作:-

    <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>
    

    【讨论】:

    • 感谢您为我提供的帮助。很抱歉,我答复晚了。我在这里有疑问,如果需要捕获批处理 mule 的异常处理应该如何,输入阶段中的 bcz 异常指向完成阶段,并且流程阶段有其单独的(唯一失败)来处理异常。那么我如何像其他正常流程一样全局捕获异常。
    • 您的 MEL 提示帮助了我。
    • 只有我们可以将记录器保存在批处理完成中。我们不能给任何其他处理器。例如我需要保存已处理和失败的记录,某些情况下我需要将 InputPhase 中发生的异常外部到其他流程来处理。您建议的解决方案是什么。提前致谢。
    【解决方案2】:

    是的,您需要在 On complete Phase 中使用它作为 finally 块来收集成功和不成功的批处理结果。 https://dzone.com/articles/handle-errors-your-batch-job%E2%80%A6

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      相关资源
      最近更新 更多