Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB MDB "REQUIRED" TX Attribute  RSS feed

 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am going through an EJB book and came across this statement.
A Message Driven Bean can use 'REQUIRED' tx attribute for its onMessage method.

What my interpretation is:
If some message is delivered in a queue by some client method, and that method has initiated some transaction.
Now 'REQUIRED' attribute applied to MDB means that the client producing the message should have some transaction initiated.
Else, MDB would create a new one.

Now, only when the client tx is successful, the MDB will be motified about the message in the queue, which means the client tx is already completed when MDB 'onMessage' method is called.
So, how does 'REQUIRED' tx fit here?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your interpretation is incorrect. You have to remember that with queues, the processing is asynchronous. The client can send the message to the queue and it will be delivered. But, when the MDB takes it up for processing is in the control of the server. It may be immediate or an hour later. Basically, there is no direct link between the client and the MDB. So, it is obvious that a transaction cannot span this entire communication.

If a MDB has a @Required transaction attribute, that would mean that the code in the method runs under a transaction. For example, the MDB might process the message and write it to a DB - so, you can wrap this in a transaction.
 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I got it now. Client tx will anyway be not related to MDB transaction. @Required would only mean that MDB creates a new transaction.
Thank you so mych for your explaination.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, you're welcome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!