Calling Async REST api from spring batch processor

前端 未结 1 684
说谎
说谎 2021-01-06 04:39

I wrote a spring batch job that processes List of Lists.

Reader returns List of List. Processor works on each ListItem and returns processed List. Writer writes stu

相关标签:
1条回答
  • 2021-01-06 04:49

    I did read about AsyncItemProcessor and AsyncItemWriter, but I am not sure if that is something I should use in this scenario.

    Yes, AsyncItemProcessor and AsyncItemWriter are suitable for your use case. The AsyncItemProcessor will execute the logic (your rest call) of the delegate ItemProcessor for an item on a new thread. Once the item completes, the Future of the result is passed to the AsynchItemWriter to be written. The AsynchItemWriter will then unwrap the Future and write the item. The advantage of these components is that you don't have to deal with Futures wrapping, unwrapping, etc yourself.

    You can find:

    • More details here: https://docs.spring.io/spring-batch/4.0.x/reference/html/spring-batch-integration.html#asynchronous-processors
    • An example here: https://github.com/mminella/scaling-demos/blob/master/single-jvm-demos/src/main/java/io/spring/batch/scalingdemos/asyncprocessor/AsyncProcessorJobApplication.java

    Hope this helps.

    0 讨论(0)
提交回复
热议问题