Jul 7th, 2009, 11:07 AM
Writing exceptions to a 'transactional' file?
I'm using SB2 and have a simple batch job reading from a db, transforming and writing items to a file. Then a tasklet sends the file to destination via file transfer.
Errors in the processor need to be written to a different file and this file is going also going to be sent onward.
Is there a recommend way to do this?
I could implement SkipListener.onProcessError and write to the error file from there, but what would happen if job was going to be restarted after a crash - is there any way of getting the state of the file into the context?
With this in mind would it be better to try and implement a CompositeItemWriter to manage writing to both files. This would maintain state for me I think. If I go this way is there any SB support to help me catch the process exceptions or do I need to implement my own exception handling within the processor to catch and return my 'ExceptionItem'?
Last edited by ndw; Jul 7th, 2009 at 11:11 AM.
Reason: Improve Clarity
Jul 9th, 2009, 03:48 AM
You can use a file ItemWriter (flat file or XML) in an SkipListener or a composite writer (it doesn't matter, since they both only get called in a committed transaction once). The framework item writers synchronize buffer flushes on the transaction, so they are not truly transactional, but in normal circumstances it behaves the way you want I think (i.e. as long as the transaction either commits or rolls back successfully). The ItemProcessor is also a possibility, but there is some ambiguity about how many times an item can be processed and committed. If you try it and it works that's great - I'd be glad to hear.
Jul 10th, 2009, 11:04 AM
I'll try injecting ItemWriter into SkipListener - I don't want to implement my own exception handling if I can avoid it. I assume I need to use the ItemStream interface to register my Writer with the Step? I'll try this anyway.
I don't see any need to do the write from within ItemProcessor so I won't be trying this (sorry).