Best approach using Spring batch to process big file

北战南征 提交于 2019-11-28 06:33:09

问题


I am using Spring batch to download a big file in order to process it. the scenario is pretty simple:

1. Download the file via http
2. process it(validations,transformations)
3. send it into queue
  • no need to save the input file data.
  • we might have multiple job instances(of the same scenario) running in the same time

I am looking for best practice to handle this situation.

Should I create Tasklet to download the file locally and than start processing it via regular steps?
in that case I need to consider some temp-file-concerns (make sure I delete it, make sure i am not overriding other temp filename, etc..)

In other hand I could download it and keep it in-memory but than I afraid that if I run many jobs instances ill be out of memory very soon.

How would you suggest to nail this scenario ?? Should I use tasklet at all?

thank you.


回答1:


If you have a large file, I'd recommend storing it to disk unless there is a good reason not to. By saving the file to disk it allows you to restart the job without the need to re-download the file if an error occurs.

With regards to the Tasklet vs Spring Integration, we typically recommend Spring Integration for this type of functionality since FTP functionality is already available there. That being said, Spring XD uses a Tasklet for FTP functionality so it's not uncommon to take that approach as well.

A good video to watch about the integration of Spring Batch and Spring Integration is the talk Gunnar Hillert and I gave at SpringOne2GX. You can find the entire video here: https://www.youtube.com/watch?v=8tiqeV07XlI. The section that talks about using Spring Batch Integration for FTP before Spring Batch is at about 29:37.




回答2:


I believe below example is a classic solution to your problem http://docs.spring.io/spring-batch/trunk/reference/html/springBatchIntegration.html#launching-batch-jobs-through-messages



来源:https://stackoverflow.com/questions/27729750/best-approach-using-spring-batch-to-process-big-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!