Spring批量读取并重试xml列表上的failuire(而不是整个文件)

时间:2015-08-21 18:41:11

标签: spring spring-batch batch-processing

我有一个示例输入文件,如下所示。我希望spring批处理它并重试异常。但是,处理和重试不应该在整个输入上,而是在列表(记录)级别。例如,在处理记录1001,1002& 1003,如果1002失败,那么弹簧批次应该重试三次,然后再进入1003。

<company>
    <record refId="1001">
        <name>mkyong</name>
        <age>31</age>
        <dob>31/8/1982</dob>
        <income>200,000</income>
    </record>


<record refId="1002">
        <name>kkwong</name>
        <age>30</age>
        <dob>26/7/1983</dob>
        <income>100,999</income>
    </record>

    <record refId="1003">
        <name>joel</name>
        <age>29</age>
        <dob>21/8/1984</dob>
        <income>1,000,000</income>
    </record>
   . . . . . . 
</company>

Spring batch Config。

parent="basedStep">
        <batch:description>For sending out alerts</batch:description>
        <tasklet>
        <chunk reader="cam.ingestedFile.reader" processor="cam.ingestion.pps.processor" retry-limit="3" commit-interval="1" skip-limit="${batch.tolerance.skip.limit}" > 

             <skippable-exception-classes>
                <include class="com.cam.exception.EBNoAcknowledgementException"/>                   
            </skippable-exception-classes>      
            <retryable-exception-classes>
                <include class="com.cam.exception.EBNoAcknowledgementException"/>
            </retryable-exception-classes>
        </chunk>        
            <transaction-attributes isolation="READ_COMMITTED" ></transaction-attributes>
        </tasklet>

    </batch:step>

1 个答案:

答案 0 :(得分:1)

将读者修改为关注并且有效:

<bean id="cam.ingestedFile.reader"class="org.springframework.batch.item.xml.StaxEventItemReader">
    <property name="fragmentRootElementName" value="record" />