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!! :)

