Alessandro
Alessandro

Reputation: 137

Spring Batch: write failed records in DB table

i have to implement a Spring Batch in which i have to elaborate data coming from an input table and write the result of the elaboration in an output table... up to now ok.

I have the following requirement: if the elaboration of some records fails (either in reader, processor or writer), i have to write those records in a "failed record" table.

The question is: which is the best way to do that?

Thanks Alessandro

Upvotes: 2

Views: 1652

Answers (1)

Jose Luis Martin
Jose Luis Martin

Reputation: 10709

I supose that you are skiping failed items so a SkipListener will work fine.

Something like

public class StoreFailedRecordsSkipListener implements SkipListener<A, B> {

    @Override
    public void onSkipInRead(Throwable t) {

    }

    @Override
    public void onSkipInWrite(B item, Throwable t) {
        // save processed item
    }

    @Override
    public void onSkipInProcess(A item, Throwable t) {
        // save read item
    }

}

Upvotes: 3

Related Questions