File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes MDB Enthuware Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "MDB Enthuware Question" Watch "MDB Enthuware Question" New topic
Author

MDB Enthuware Question

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
The developer of an MDB wants to ensure that a message is redelivered if the onMessage method of the bean throws RuntimeException, then he should use CMT with transaction attribute REQUIRED.

Please explain


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Jun Liu
Greenhorn

Joined: Nov 15, 2005
Posts: 11
If using CMT, MDB can only have REQUIRED and NOT_SUPPORTED. The message can only be redelivered when there is a transaction and the transaction has been rolled back. RuntimeException can cause a transaction to be rolled back. So we need to ensure there is a transaction. If using NOT_SUPPORT, there won't be a transaction. So we can only use REQUIRED.

If using BMT, see the ejbcore spec 5.4.12:
When a message-driven bean using bean-managed transaction demarcation uses the javax.transaction.
UserTransaction interface to demarcate transactions, the message receipt that causes
the bean to be invoked is not part of the transaction.

So the transaction rollback won't cause the message to be redelivered.
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
I see no evidence that the statement
The developer of an MDB wants to ensure that a message is redelivered if the onMessage method of the bean throws RuntimeException, then he should use CMT with transaction attribute REQUIRED.

is correct. Also the argument based on core spec 5.4.12 from Jun Liu doesn't seem to be really convincing to me. For, core spec 5.4.17 says

If a message-driven bean uses bean-managed transaction demarcation and throws a RuntimeException, the container should not acknowlegde the message.

According to core spec 5.4.14 a JMS-MDB with BMT can use the acknowledge mode AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE and according to JMS 1.1 spec 4.5.2:
The result of a listener [that's the MDB in our context, remark by me] throwing a RuntimeException depends on the session's acknowledge mode.
AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE - the message will be immediately redelivered. The number of times a JMS provider will redeliver the same message before giving up is provider dependent.

In my words: If the onMessage method of a MDB with BMT throws a RuntimeException, then the container doesn't acknowlege the method. And because of a missing acknowlegement the JMS provider redelivers the message.

Therefore I see no need to use CMT in order to ensure message redelivery due to a RuntimeException.

The situation changes if one has the stronger requirement that message redelivery should be ensured if a transaction rollback occurs: Then one has to use CMT as explained by Jun Liu above.


SCJP 5 (98%) - SCBCD 5 (98%)
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
That was a question from enthuware!

Perhaps the simulator wanted to ask a question like Q 12 of the sun's proficiency test posted here. This says -

If a CMT MDB's onMessage message method roll backs the transaction, then the message is redelivered. Ans as Promod pointed out in his test code, the message is redelivered 6 times on JBoss4.x

Is Enthuware trying to ask something similar but it mixed up the BMT MDB on mMessage RunTimeException with a CMT MDB onMessage transaction rollback?



Promod kumar
Ranch Hand

Joined: Jun 26, 2006
Posts: 90
Ralph said
The situation changes if one has the stronger requirement that message redelivery should be ensured if a transaction rollback occurs: Then one has to use CMT as explained by Jun Liu above.


This is getting really confusing . When using BMT and there is a SystemException, the message is redelivered multiple times. When there is a SystemException for a BMT MDB one of the actions that the container does is to rollback the transaction. Does this mean that message redelivery is also guaranteed even using BMT when a transaction rollback occurs. Can someone clarify
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Does this mean that message redelivery is also guaranteed even using BMT when a transaction rollback occurs.
It depends on how the rollback encounters: If the transaction is rollbacked because of a RuntimeException then the message is redelivered as explained above. If the rollback is caused by userTransaction.setRollbackOnly() or userTransaction.rollback() then the message isn't redelivered.

Hope this helps.
Promod kumar
Ranch Hand

Joined: Jun 26, 2006
Posts: 90
Ralph, Thanks for the response, that helps a lot. I tried it in Jboss 4.2.2 and I was able to test both cases, message was not redelivered when setRollbackOnly() was used.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB Enthuware Question