1

I am having a task where I am processing items by Spring Batch. Reading items from database and using chunks with commit-interval set to 1000. But after each chunk I need to send a notification to another system with the information about the processed chunk (i.e. some information about each item in one message).

I was thinking about using ChunkListener.afterChunk but I think the problem is with passing IDs of 1000 items to step context / job parameters. Also I could think of some performance issues as each item must be again read from database by its ID (I would avoid IN clause for a thousand IDs).

Does anyone have a hint how this could be solved? Is there some easy way of passing chunk items/ids? Or is Spring Batch suitable for this type of functionality?

Zis
  • 162
  • 16
  • 1
    [This](https://stackoverflow.com/questions/18915688/multiple-itemwriters-in-spring-batch) might be helpful. – Andrew S Nov 18 '19 at 16:03
  • @AndrewS thanks for the example. I think this might be used as one writer saves changes to db and the other send the notification for all items. – Zis Nov 19 '19 at 10:46
  • Or I was thinking about ItemWriteListener.beforeWrite() so when the chunk is about being stored then the notification for all of them is sent from that listener method. If it fails both are rollbacked. – Zis Nov 19 '19 at 10:48
  • 1
    I believe `ItemWriteListener#afterWrite` is appropriate for your use case. You get the list of items that were written and you can send a notification for them. – Mahmoud Ben Hassine Nov 19 '19 at 10:53

0 Answers0