EJB/MDB/JMS Concurrency problem, in need of suggestions/input.

I have a rather unique scenario in which I thought using MDB's would be a great approach, but am now having my doubts. Maybe you guys can give some positive, or negative, input on this....

We have an oracle database setup on the back end, and I am using EJB 3.0 Sessios Beans and JPA to provide the business logic and persistence to the database. We have devices setup around a building which are intended to provide status updates on given users. I figured no problem, I'll throw up a MDB on the app server and it will just take the contents of a JMS message and pass it off to the appropriate method on me Session Bean(s).

Well after implementing it, we were having massive problems. Then it hit me. The relational constraints in the database require certain updates to be processed before others. These updates were being sent off by the devices in proper order, but JMS would toss them off into the MDB pool, where they could propagate out of order due to the MDB pool/concurrency. One message might happen to process slightly faster than another for a number of reasons, and therefore the messages can get out of order. Not good.

A simple solution to this was to limit the MDB pool to 1. This prevents more than a single message coming in at a time and getting out of order. Also, when the MDB calls the appropriate Session Bean method, it is a blocking call. Therefore the MDB cannot process another message until the Session Bean has completed, which in turn means no more than a single Session Bean is ever in use at one time. So this fix completely removes concurrency, and in my mind, this creates a bottleneck.

So what might some of you guys suggest? I thought about creating a separate topic/MDB for each device, that way each device has its own single non-concurrent pipeline to the system, but overall creating a semi-concurrent system. However this is extremely impractical since there could be dozens, or possibly even hundreds of these devices providing updates, and they need to be easily added/removed from the system. Therefore we are moving towards removing the MDB approach entirely, and just implementing some sort of custom thread-pooling mechanism that would listen to JMS and pop off threads to make a call to the Session Bean for incoming messages.

If you have any suggestions, please, SUGGEST!! :)

[2365 byte] By [Smilera] at [2007-11-27 1:28:37]
# 1

These kinds of dependencies between messages do need to be handled at the application level.

There needs to be enough information in the messages themselves for the MDB to determine

whether it can proceed with a particular action. That decision might also involve querying the database, either to the existing domain tables or some new dedicated persistent data that is used

only to track the progress of the actions.

If the MDB does need to delay some action because it depends on an earlier action that has not

completed, it can create an EJB Timer event for that action and then return. (Of course the

session bean could do that too). That prevents the blocking problem.The EJB Timer "info" object

can be used to capture all the details of the action that needs to be performed and its

dependency information in case another delay is required.

--ken

ksaksa at 2007-7-12 0:26:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...