Mule Batch Job
(Part 1)
Introduction
In this post I will show a sample demo application that illustrates mule batch job working and techniques to handle exceptions and records failures. The demo application code can be cloned here Ref[1].
Use case
The application illustrates a use case of a batch job that queries a database to get all users with a status "Approved" and if any exist gets each user account record and generates a CSV file using the account attributes. The resulting CSV file will be saved for later use or it may be sent via email or sent to an FTP server.
Based on this use case, the demo application shows also how to handle some special cases that throw exceptions and lead to record failures. As an example, how to handle an approved user with no existing account? how to keep track of these failed records? and how to generate a report for approved users with no created account or send them with the exceptions to a JMS queue.
The post found here Ref[2] has a very cool explanation of exceptions and errors handling within mule batch jobs.
Description
The demo application uses the following configuration that means the batch job will continue running all the current loaded records no matter how many records have been failed.
<batch:job name="users-accounts-batch-job" max-failed-records="-1">
In other scenarios, we may need to stop the running batch job when we reach 20 failed records by setting the attribute max-failed-records=20
Input phae:
In this phase we call a flow that loads all approved user:
<batch:input>
<flow-ref name="get-users-records" doc:name="Flow Reference"/>
</batch:input>
The reference to the flow get-users-records:
<flow name="get-users-records" doc:name="get-users-records" processingStrategy="synchronous">
<logger message="Start getting users records -connecting to database using URL:${database.url}"
level="INFO" doc:name="Logger"/>
<db:select config-ref="MySqlDatabase" doc:name="get approved users"/>
<db:parameterized-query><![CDATA[SELECT * FROM usermodel.Users WHERE status=10;]]>
</db:parameterized-query>
</db:select></flow>
<logger message="End getting users records #[payload]" level="INFO" doc:name="Logger"/>
</flow>
Very nice information on Mulesoft. You can also check goformule.com for mulesoft tutorials
ResponderEliminar