Announcement Announcement Module
Collapse
No announcement yet.
Item Recovery? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Item Recovery?

    Hi,
    My requirement is that i want to store failed items into the database once the retry is exhausted. I set the itemRecoverer into the step definition. But it is not getting called. I think this happens because i am not setting the recoverableExceptionClasses property in AbstractStatefulRetryPolicy. I don't know how to set that. Can anyone tell me how to set that? I am using spring-batch 1.0.1 version .

    This is my bean definition
    Code:
     
    <bean id="retryStep" class="org.springframework.batch.core.step.item.StatefulRetryStepFactoryBean"
    		 abstract="true" >
    		<property name="allowStartIfComplete" value="true" />
    		<property name="transactionManager" ref="xaTransactionManager" />
    		<property name="jobRepository" ref="simpleJobRepository" />
    		<property name="commitInterval" value="10" />
    		<property name="skipLimit" value="1000"/>
    		<property name="listeners" ref="batchStepListener"/>
    		<property name="retryLimit" value="1"/>
    		<property name="retryableExceptionClasses" value="java.lang.Exception"/>
    		<property name="backOffPolicy" ref="backOffPolicy"/>
    	</bean>
    
    	<bean id="accountProcessingStep" parent="retryStep">
    		<property name="retryLimit" value="2"/>
    		<property name="listeners" ref="accountListenerAndRecoverer"/>
    		<property name="itemRecoverer" ref="accountListenerAndRecoverer"/>	
    	</bean>
            <bean id="accountListenerAndRecoverer" class="com.om.dh.batch.account.item.AccountItemRecoverer">
    		<property name="jdbcTemplate" ref="batchJdbcTemplate"/>
    	</bean>
    And this is my java class which acts as recoverer as well as step listener. I hope there won't be any issues here because of that.

    Code:
    public class AccountItemRecoverer extends AbstractBatchStepListener implements ItemRecoverer {
    
    	private static final String CREATE_BATCH_ACCOUNT = "INSERT into BATCH_JOB_ACCOUNT(JOB_NAME, ACCOUNT_ID," +
    	" IS_PROCESSED, REJECT_REASON)"+" values (?, ?, ?, ?)";
    
    	
    	public boolean recover(Object accountId, Throwable cause) {
    		String jobName = stepExecution.getJobExecution().getJobInstance().getJobName();
    		jdbcTemplate.update(CREATE_BATCH_ACCOUNT, new Object[]{jobName,accountId,0,cause.getMessage()});
    		return true;
    	}
    
    }
    Please note that my recover() method returning true here. what will happen to the current transaction?.

    regards,
    Ramkris

  • #2
    I think 1.0.1 gives preference to skip over retry, so all your errors are being skipped, and the recoverer is never called. If you set the skipLimit to 0, or make the retryableExceptions distinct from the skippableExceptions does that work?

    (1.1 has less of a distinction between skip and retry, so there isn't the same problem - it just calls the skip listener on an exhausted retry. If you could try a snapshot from 1.1 it would be interesting to see the result.)

    Comment

    Working...
    X