Team,
I am doing a technical poc for reading records from a flat file and inserting the data to database.
I am using chunk task and running this job using spring batch admin successfully.
I have to implement the retry policy along with a feature to set the time interval between each retry. I am stuck up with setting the time interval between each retry as chuck doesn't support it directly. Is there any work around for this?
My code is
<batch:job id="importDataJob" job-repository="jobRepository">
<batch:step id="importDataStep">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="dataReader" writer="dataWriter" commit-interval="1" retry-limit="3">
<batch:retryable-exception-classes>
<batch:include class="javax.naming.ServiceUnavailableException" />
</batch:retryable-exception-classes>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
When the job having error, is to be recovered by only re-running the target job, tasklet model can be chooseed to make recovery simple. In chunk model, it should be dealt by returning the processed data to the state before executing the job and by creating a job to process only the unprocessed data.
Spring Batch collects items one at a time from the ItemReader into a configurable-sized chunk. Spring Batch then sends the chunk to the ItemWriter and goes back to using the ItemReader to create another chunk, and so on, until the input is exhausted.
In Spring batch, the Tasklet is an interface, which will be called to perform a single task only, like clean or set up resources before or after any step execution. In this example, we will show you how to use Tasklet to clean up the resource (folders) after a batch job is completed.
Remote ChunkingThe manager is an implementation of a Spring Batch Step with the ItemWriter replaced by a generic version that knows how to send chunks of items to the middleware as messages.
In your case the configuration will look like:
Spring Batch 2.x
<bean id="stepParent" class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean" abstract="true">
<property name="backOffPolicy">
<bean class="org.springframework.batch.retry.backoff.FixedBackOffPolicy"
<property name="backOffPeriod" value="2000" />
</bean>
</property>
</bean>
<batch:job id="importDataJob" job-repository="jobRepository">
<batch:step id="importDataStep" parent="stepParent">
...
</batch:step>
</batch:job>
Unfortunately, batch
namespace does not support setting backOffPolicy
directly to step
, see BATCH-1441.
Spring Batch 3.0
In Spring Batch 3.0 some classes have moved to other packages. This is the the configuration fragment:
<bean id="stepParent"
class="org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean"
abstract="true">
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
<property name="backOffPeriod" value="2000"/>
</bean>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With