Reputation: 63
I need help from experienced Spring Batch programmers for a particular problem I am having.
I am new to Spring Batch. It has detailed documentation for each class or interface, but next to nothing in all of it working together.
The Scenario:
I have a database hosted on the cloud, So I have to make REST calls to get some data from it and save related data to it.
- Data retrieval will return a JSON response with data I queried.
- Data save will return a JSON response on how many rows were added etc.
- All responses will have a valid HTTP status code.
- A transaction is complete when the save call is successful with an Http code of 200 and data which shows how many records were inserted is received.
The connection may not always be available, In that case the program must keep retrying every 5 minutes until the whole task is complete.
What I chose not to do
I could do some dirty Java tricks (which were surprisingly recommended by many in stack overflow)
What I tried
So I decided to use Spring Batch since it seemed to be a framework made for this.
I have no file tasks, so I used a Tasklet instead of Readers and Writers.
The Tasklet interface can return only FINISHED status code. No codes for FAILURE
So, inside the tasklet, I set a custom value in the StepContext and retrieved my custom value in a StepExecutionListener and accordingly configured ExistStatus of the Step to FAILURE
To handle this workaround I had to configure a JobExecutionListener to make the Job fail accordingly.
Apart from all these above work-arounds,
The Question
Is Spring Batch right for this situation?
Is my design correct? It seems very "hack"-ey.
I need help with the most efficient way to handle my scenario
Upvotes: 1
Views: 644
Reputation: 9374
I was using spring batch for similar case - as a execution engine to process large files which resulted as lots of REST requests to other systems.
What Spring batch brought for me:
More on business cases here: https://docs.spring.io/spring-batch/trunk/reference/html/spring-batch-intro.html#springBatchUsageScenarios
So you need to check carefully those business cases and answer yourself if you really need them. So far what you have described - I really don't see benefit of spring batch for you.
Upvotes: 1