-1

Am having an inbound database endpoint am selecting records with a condition which returns 500 rows as result set.Now i want to insert the coloumns in another DB.I used the batch process and have two batch steps selecting data and inserting data. Now if while selecting data any error occurs I have to send a mail and If while inserting if it fails I need to log it in a different place.So how can I create two different exceptions for each step am not able to use catch exception in batch process.For now am using a flow reference inside batch step and handling the exception.Please provide me a better way.AM using batch execute -> batch -> batch step -> flow reference->exception handling

 <batch:job name="BOMTable_DataLoader">
    <batch:process-records>
        <batch:step name="SelectData">
            <flow-ref name="InputDatabase" doc:name="InputDatabase"/>
        </batch:step>
        <batch:step name="InsertData">
            <batch:commit size="1000" doc:name="Batch Commit">
                <flow-ref name="InserDatabase" doc:name="UpdateDataBase"/>
            </batch:commit>
        </batch:step>
    </batch:process-records>
    <batch:on-complete>
Satheesh Kumar
  • 797
  • 7
  • 31

1 Answers1

0

For 500 rows only I will not use a batch processing you could simply create with an iteration a SQL script with all the insert in one shot and execute it via the database connector.

If you want to know which insert fails than you could use foreach processor to iterate over the rows and insert them one by one so that you can control the output, it will be slower but it all depends on your needs.

Just use the right type of query depending on your needs and remember you can use MEL in your query. Just pay attention to injection if your input are also coming from untrusted sources (if you use parametrized query than you are on the safe side becouse parameters are escaped)

More on the db connector https://docs.mulesoft.com/mule-user-guide/v/3.7/database-connector


I do confirm after your question update that the only way to handle exception is the way you use it. The fact that the module in mule is called "Batch processing" does not mean that everytime you have something that looks like a batch job you need to use that component. When you got some complex case just don't use it and use standard mule components like VM async for a async execution and normal tools like foreach or even better collection splitter and get all the freedom and control over exception handling.

Mauro Rocco
  • 4,980
  • 1
  • 26
  • 40