2

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

NitishDeshpande
  • 435
  • 2
  • 6
  • 19
  • You need a spring batch if the 4 service is triggered as a scheduled job. Rest Controllers needs to be used if the 4 service calls are triggered by a user of your application. – ArunM Apr 17 '16 at 11:24
  • The answer should be obvious depending on your Use Case – ArunM Apr 17 '16 at 11:24

2 Answers2

3

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

Valerio Vaudi
  • 4,199
  • 2
  • 24
  • 23
0

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.

Horsing
  • 1,070
  • 7
  • 22