Search code examples
spring-batchjsr352java-batchjberet

Content based routing and java batch JSR 352 (jBeret, Spring Batch)?


Content based routing and java batch JSR 352 (jBeret, Spring Batch)?

Have tried to implement some simple "real world" batch jobs because the "hello world" was looking promising. Seems that I haven't got the concept right - but the actual release seam pretty useless for "real world" examples.

- read 5mio lines (ItemReader works fine)
- write to three different filed/resources based on the content of the line read

The "intuitive" way would be to:

  • configure three writer (e.g. ItemWriterA, ItemWriterB, ItemWriterC). BUT: onle one writer is possible in a chunks - why this restriction?

  • add a decision and use the writer based on your decision. BUT: decisions can't be included in cunks - why this restriction?

What's the right approch doing this with Java Batch JSR 352? Any hints are welcome.

Java Batch - as could be


Solution

  • You would need to implement the logic in a single ItemWriter. The specification-defined framework doesn't help you here. SpringBatch has a CompositeItemWriter which helps with this sort of use case, though it is specific to SpringBatch and won't work with other JSR 352 implementations like Liberty (or, as far as I know, JBeret).

    One rationale for not including "child writers" in the spec was, as in your case, the idea that there'd be app-specific logic to decide to write (or not) to the children. But it's an area where JSR 352 could use more samples and probably enhancement of the spec itself.

    That's not a great answer, but I didn't want to leave the question without an answer.