Spring batch or Spring boot async method execution

2019-08-13 02:38发布

I have a situation where the data is to be read from 4 different web services, process it and then store the results in a database table. Also send a notification after this task is complete. The trigger for this process is through a web service call. Should I write my job as a spring batch job or write the whole read/process code as an async method (using @Async) which is called from the Rest Controller?

Kindly suggest

2条回答
Deceive 欺骗
2楼-- · 2019-08-13 03:13

If there are large amounts of services should be executed, spring-batch would be the choice. Otherwise, I guess there is no need to import spring-batch.

In my opinion, @Async annotation is the easier way.

If both methods can work, of course simpler the better.

At the end, if there will be more and more service not only 4, spring-batch would be the better solution, cause spring-batch are professional in this.

查看更多
等我变得足够好
3楼-- · 2019-08-13 03:16

In my opinion the your choice should be @Async, because Spring Batch was designed for large data processing and it isn't thought to processing on demand, typically you create a your batch and then launch the batch with a schedule. The benefit of this kind of architetture will be the reliability of your job that colud restarted in case of fail and so on. In your case you have a data integration problem and I can suggest to see at Spring Integration. You could have a Spring Integration pipeline that you start through a rest call.

I hope that this can help you

查看更多
登录 后发表回答