1
votes

I'm using batch in mule for the first time, not sure how to handle the exceptions for batch records.

Records getting failed input phase, but not able to catch failure exception either in input phase logger and also in Batch step( Failure flow)logger. Perhaps MEL #[inputPhaseException] itself throwing exception.

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

Is there is any restriction for batch MEL to be used only inputphase and certain MEL on Process Record and Complete. Because i tried keep most of the get..Exception{} in Failure flow, it is throwing error. Please suggest, Thanks in advance.

2

2 Answers

1
votes

Yes .. you are right .. #[inputPhaseException] is causing all the issues .. I have modified your Mule flow and you can try the following :-

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

Yes, You need to use in The On complete Phase as it acts Finally block to collect the Successful and Unsuccessful Batch results. https://dzone.com/articles/handle-errors-your-batch-job%E2%80%A6