Reputation: 7613
We have a situation where we are reading from JMS(may be with RabbitMQ in the future) and process to get the data. Then we use that data to call a web-service (another reading). Lastly we take the data from the web-service and write it to another JMS. So there are 2 readings in this scenario.
We have already done the first reading and process part. I have also seen that there are ways to use MultipleWriters. However, how can we use multiple readers ? Do we have to include the last reading part in the process?
Correct us if we are using the wrong approach. It's our first time implementing Spring Batch. I appreciate if you can include a sample scenario.
Upvotes: 0
Views: 4258
Reputation: 1756
There is not a built-in notion of Multiple Readers in Spring Batch.
I think your best option is to include the web service call as part of the process stage in your batch. Try not to think of it as a being a "read", but more of a "transformation". Since you have already written a processor, I would recommend looking into keeping the web service call as it's own separate processor in a processor chain.
On a side note, generally when I think of having two different readers, that might be a sign to consider two separate batch jobs altogether that may reuse some components if they are similar in their processing or writing. Splitting into two jobs for your project seems like it would be overkill, but could be useful in the case that you wanted to do something like aggregate JMS messages received in some sort of data structure, and make single web service calls for groups of messages instead of a web service call for each message.
On another side note, you may want to investigate Spring Integration if you are not set on going solely with a Spring Batch solution. Spring integration may be more suited to your needs as it is built around messaging and you are writing to and from JMS pipes. You could actually use a combination of Batch and Integration if you felt inclined.
Upvotes: 0
Reputation:
I think you are probably talking about having more than one Step.
For instance, you already did what you did in step1
, then you can do something else (like another group of "actions") in the step2
. Notice that the 'job` will encapsulate your entire batch process.
You can definitely have multiple "steps" for the same "job".
Upvotes: 1