Reputation: 792
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>
Upvotes: 7
Views: 12909
Reputation: 10639
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>
Upvotes: 7