I have a slight problem involving message driven beans here :
"ReaderMDB" listens on topic "Magazine" for messages containing "Reader" in
the message-property "Receiver-Classes".
It is a messagedriven bean able to handle state information in a database.
When a message comes in, it holds the property "Reader-ID", which tells the MDB which user it is addressed for.
ReaderMDB is representing a user.
Since I cannot deploy one MDB for every user in the system, I have to "incarnate" the user at instantiation time, by extracting "Reader-ID", and the execute actions in behalf of this user !
The problem I face here is the following :
- how can I make sure that only ONE ReaderMDB instance is acting in behalf of a user at a time ?
For now, I "solved" this problem this way :
I have deployed a messageDispatcher for ReaderMDBs.
This dispatcher gets the message addressed to Readers, extracts the Reader-ID, locks the "readers-desk" by updating a field there, and then reissues the message.
This happens in one transaction.
Then, a ReaderMDB gets the message.
onMessage() does the following :
- reads message-property "Reader-ID" to know which customer the ReaderMDB
- reads from table "readers-desk" : if the appropriate record is showing
"instance activated", then it must die and the message must remain in the
topic for consumption ! (the purpose is not to have 2 ReaderMDBs
representing the same "Reader" updating their state at the same time !!)
- updates table "readers-desk" with "instance activated"
- does some message postings to the topic.
- does some other database reads and updates
- updates appropriate record in table "readers-desk" with "no instance
Well, from what I understood from the specification of MDBs and JMS, it is
possible to do all this atomically.
Imagine an exception is thrown in the onMessage method :
1) updates to databases will BE rolled back if an exception occurs within
this - is this true for JBoss/JBossMQ ?
2) consumption of the message will be "rolled back", so that another
instance may consume this message later from the topic "Magazine".
3) message postings done within onMessage will also be rolled back.
Am I right here ? The problem is : we cant afford commercial products to
support this. I hoped this was supported by JBoss and JBossMQ.
4) what happens if the MDB issues a message to the topic it had consumed
from ? will this be rolled back ? will this be possible at all ?
5) what happens if the MDB issues a message to the topic it had consumed
from, and this message may be a message to itself. Does this open up any
Best regards, Jubin