Grouping/summarizing spring-batch records

廉价感情. 提交于 2019-12-19 11:17:49

问题


I'm new to spring-batch and I want to use it to implement the following proces:

read: a list of items from webservice
process: groups these items
write: these groups back to webservice

Example:

Input:
transactionID, store, amount
1, FooStore, 2.50
2, BarStore, 19.99
3, FooStore, 12,49

Output:
totalsID, store, amount
1, FooStore, 14.99
2, BarStore, 19.99

Is this even possible using spring-batch, am I missing an important step, or does this conflict with the concept of batch processing to such an extent that I should look for a different solution?

I have found a possible solution, that is by using the writeFooter method, but that seems silly because I fear I'll lose a lot of the benefits of using spring-batch like the error recovery and memory management. Plus as far as I can see the footer is only supported if the output is written to a file, not send to a webservice.


回答1:


Write a job with two steps:

  1. Read every record and from input then, in your own ItemWriter.write(), update a summary table
  2. Dump your summary table to text file (or webservice)

You can also try to reach the goal writing a single SQL statement using aggregate function like SUM() and COUNT() then, with a single-step job, read every record generated from custom SQL and write directly to you text file (or webservice).



来源:https://stackoverflow.com/questions/19906772/grouping-summarizing-spring-batch-records

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