Spring Batch - Simple Async & Polling
here's a use case a client came upon; they were going to use a Spring Batch Tasklet to call a service that would do some file processing. The call to the remote service, if synchronous, would cause a transaction timeout in the Spring Batch world namely because the file processing service would take so long (let's say 10 mins).
to solve this, we looked at the RepeatStatus of the Tasklet as a 'polling-type' solution. that is, we wouldn't allow the Tasklet to continue until we've gotten back an 'ok' from the service. The service was then launched as FutureTask which sorted that out.
so, in the name of preserving this solution, here's the example
first the service interface that we want to call from batch
then the implementation
note: the BasicService class inside it is the dummy service
now a very very simple task let (place holder really)
and here's where the 'polling' happens
note: there's a pollingInterval set that allows for the tasklet to 'pause' before trying again
now here's the glue part - the batch job definition itself
and the resources as well
finally, here's a unit test to make sure it works
and to help get the project going, the maven pom too
first the service interface that we want to call from batch
then the implementation
note: the BasicService class inside it is the dummy service
now a very very simple task let (place holder really)
and here's where the 'polling' happens
note: there's a pollingInterval set that allows for the tasklet to 'pause' before trying again
now here's the glue part - the batch job definition itself
and the resources as well
finally, here's a unit test to make sure it works
and to help get the project going, the maven pom too
No comments:
Post a Comment