EJB 3.0 Architecture Question - Batch process to concurrent process
posted 6 years ago
I have an architecture type question for an EJB 3.0 app.
Currently, I have an session bean that runs on a time. Every X minutes it wakes up and does the following.
1. Reads some records from a database.
2. Loops through each record
While looping through each record it:
1. Makes a connection to web server A to download information.
2. Makes a connection to web server B to deliver information.
3. Updates record
This works fine when the number of records is relatively low. But I'm looking for a better way to be able to scale the application. The number of records that need to be processed in each cycle is growing and can result in more work in the allotted time. The bottleneck is the communication between web server A and B, there is little computational processing going on. So I need to be able to process multiple records simultaneously, but at the same time make sure that the same record isn't processed more than once.
I'm fairly new to EJB design, so am looking for some suggestions.
One thought I had was to move the work done in the loop into a message bean. Meaning the timer just reads the database records and fires off a message for each record to be processed. But I'm not sure how the server would actually handle this. Would it process multiple messages simultaneously? I think it would. If so, does it have a queuing mechanism or would it try to process them all at once? I want to have this done as quickly as possible but not bring the server to its knees. Would I be able to poll to see if my messages have completed or not? I'd want to avoid sending duplicate messages (i.e. Avoid a timer firing a second time that sends off the same records to be processed that are currently in the server's message queue).
Thoughts, suggestions or recommended documentation is appreciated. I have a few books, but they cover things at a lower level and don't get into recommended design.