为Spring Batch中的每个输入文件从文件目录创建输出文件。

huangapple go评论68阅读模式
英文:

Create output file for each of input file from directory of files in Spring Batch

问题

我有一个包含交易信息的CSV文件目录。
我需要读取每个文件,处理一些业务逻辑(与数据库验证以检查帐户和交易是否有效),并将有效交易写入新的输出文件。

输入:
Tranx_100.csv,Tranx_101.csv,Tranx_102.csv...

输出:
Tranx_100_output.csv,Tranx_101_output.csv,Tranx_102_output.csv...

希望使用Spring Batch来实现这一点。对如何实现这一点有什么建议吗?

对于每个文件作为输入,处理和输出是相同的 - 我可以将它们作为步骤(Step)的一部分运行,并在作业(JOB)中重复执行这个步骤吗?

英文:

I have a directory of CSV files which contains transaction information.
I need to read each file , process some business logic (validate with DB to check valid account and transaction or not) and write the valid transactions into new output file.

Input:
Tranx_100.csv, Tranx_101.csv, Tranx_102.csv....

Ouput:
Tranx_100_output.csv, Tranx_101_output.csv, Tranx_102_output.csv....

Want to use spring batch for this. Any suggestions on how to implement this?

For each file as input, process, output are same - can i run them as part of 'Step' and repeat the step for each input file in a JOB?

答案1

得分: 0

不要回答我要翻译的问题。以下是要翻译的内容:

"Instead of looping on the same step or using multiple steps in a single job, I would use a job instance for each file (ie the file is an identifying job parameter) and launch jobs in parallel. This approach has multiple advantages:

  • Fault-tolerance: In case of failure, only the failed file is re-processed
  • Scalability: You can run multiple jobs in parallel easily
  • Logging: logs will be separated by design
  • And all the good reasons of making one thing do one thing and do it well"
英文:

Instead of looping on the same step or using multiple steps in a single job, I would use a job instance for each file (ie the file is an identifying job parameter) and launch jobs in parallel. This approach has multiple advantages:

  • Fault-tolerance: In case of failure, only the failed file is re-processed
  • Scalability: You can run multiple jobs in parallel easily
  • Logging: logs will be separated by design
  • And all the good reasons of making one thing do one thing and do it well

huangapple
  • 本文由 发表于 2020年7月24日 00:52:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63059337.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定