1

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.

star
  • 1,493
  • 1
  • 28
  • 61

2 Answers2

1

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>
Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
  • Thanks for your great effort in helping me. Sorry for my late response. I have doubt here, if need to catch exception handling for batch mule how it should be, bcz excep in input phase directing to complete phase, and process phase have its separate ( only failure) to handle Exceptions. Then how do i globally capture the exception altogether as like other normal flow. – star Sep 22 '14 at 11:06
  • Your MEL hint helped me. – star Sep 22 '14 at 11:11
  • Is that only we can keep logger inside Batch Complete.Are we cant give any other processor. For example i need to save the processed and failed record, some case i need to take the exception happened in InputPhase externally to other flow to handle. What would be the solution you suggest. Thanks in advance. – star Sep 24 '14 at 01:49
1

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