aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes MDB Message Redelivery and discard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "MDB Message Redelivery and discard" Watch "MDB Message Redelivery and discard" New topic
Author

MDB Message Redelivery and discard

Tony romer
Ranch Hand

Joined: Jul 21, 2008
Posts: 32
Hey there,
I am so much confused about what happens on onMessage method of MDB. Can you answer below cases one by one?
Thanks in advance


1. onMessage (with Required attribute) calls other bean (with required also) where other bean gets a system exception.
Result : Other bean is discarded, MDB Transaction is rolledback and same message will be redelivered to onMessage method again.

2. onMessage (with Not_supported attribute) calls other bean (with required ) where other bean gets a system exception.
Result : Other bean is discarded, what happens to MDB? What it throws? Is the message redelivered to it again or is it simply discarded?

3. onMessage itself throws a system exception.
Result : MDB is discarded, it throws this system exception to container.

4. onMessage itself throws ApplicationException???
Result : ???

5. i set context.setRollBackOnly explicitliy on onMessage method with required attribute.
Result : ???
Tony romer
Ranch Hand

Joined: Jul 21, 2008
Posts: 32
any help
Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
2. onMessage (with Not_supported attribute) calls other bean (with required ) where other bean gets a system exception.
Result : Other bean is discarded, what happens to MDB? What it throws? Is the message redelivered to it again or is it simply discarded?

System Ex. - Discard the instance
No Tx - no rollback, no re-delivery


4. onMessage itself throws ApplicationException???
Result : ???

Assuming default Tx_Atrribute - Required,
App.Ex - Tx roll back, msg re-delivered.

i set context.setRollBackOnly explicitliy on onMessage method with required attribute.
Result : ???

with Required attribute - means its CMT,
context.setRollbackOnly - it can be done only with BMT,
so illegalStateException raised, bean instance discareded

Since its with Required attribute, & Tx not completed,
msg re-delivered, for sometimes but it's going to discard bean instance everytime,
so msg would be marked poison-msg & added to poison-msg queue.


Any comments?


Thanks.

Promod kumar
Ranch Hand

Joined: Jun 26, 2006
Posts: 90
with Required attribute - means its CMT, context.setRollbackOnly - it can be done only with BMT, so illegalStateException raised, bean instance discareded


I think you meant the opposite, EJBContext.setRollbackOnly can be called only by Beans using CMT. If you call it from beans using BMT you will get IllegalStateException.

As for the original question, I suggest

1) Reading section 14.3.4 from core spec
2) Trying all the scenarios out with some code.

When using BMT or CMT, if there is a system exception in the onMessage method, the message will be redelivered. If the bean uses BMT and sets the transaction to rollback, then the message is not redelivered. If the bean uses CMT (Required) and sets the transaction to rollback, then the message is redelivered.
Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
I think you meant the opposite, EJBContext.setRollbackOnly can be called only by Beans using CMT. If you call it from beans using BMT you will get IllegalStateException.

You are correct, I messed up.

And in any case I was wrong as you have mentioned in next statement.
When using BMT or CMT, if there is a system exception in the onMessage method, the message will be redelivered. If the bean uses BMT and sets the transaction to rollback, then the message is not redelivered. If the bean uses CMT (Required) and sets the transaction to rollback, then the message is redelivered.
Gladwin Burboz
Greenhorn

Joined: Feb 26, 2008
Posts: 25


1. onMessage (with Required attribute) calls other bean (with required also) where other bean gets a system exception.
Result : Other bean is discarded, MDB Transaction is rolledback and same message will be redelivered to onMessage method again.

CORRECT


2. onMessage (with Not_supported attribute) calls other bean (with required ) where other bean gets a system exception.
Result : Other bean is discarded, what happens to MDB? What it throws? Is the message redelivered to it again or is it simply discarded?

Since MDB has transaction NOT_SUPPORTED, auto commit happens as soon as message is picked up by the listener even before calling omMessage(). By the time system exception occurrs in other bean, message is already commited and hence will not be redelivered.


3. onMessage itself throws a system exception.
Result : MDB is discarded, it throws this system exception to container.

If MDB has transaction NOT_SUPPORTED, message is already commited and hence will not be redelivered..
If MDB has transaction REQUIRED, message is will be redelivered..


4. onMessage itself throws ApplicationException???
Result : ???

Application exception does not cause transaction to roll back hence message will not be redelivered..



5. i set context.setRollBackOnly explicitliy on onMessage method with required attribute.
Result : ???

MDB has transaction REQUIRED attribute hence transaction will rollback and message is will be redelivered..

<a href="http://www.sealordresortarnala.com" target="_blank" rel="nofollow">http://www.sealordresortarnala.com</a>
sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
1. onMessage (with Required attribute) calls other bean (with required also) where other bean gets a system exception.
Result : Other bean is discarded, MDB Transaction is rolledback and same message will be redelivered to onMessage method again.


In my opinion..Yes

2. onMessage (with Not_supported attribute) calls other bean (with required ) where other bean gets a system exception.
Result : Other bean is discarded, what happens to MDB? What it throws? Is the message redelivered to it again or is it simply discarded?


In my opinion..Other bean is discarded. Future course should happen, depending on how system exception is handled by MDB. If it suppresses it then nothing will happen. If it further throws it back then this MDB is discarded too. Assuming MDB is discarded, redelivery depends on Vendor.
Referring to the link, http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/cmb_trans.html
Redelivery depends on Sync Point (used in Websphere) even if there is no transaction

3. onMessage itself throws a system exception.
Result : MDB is discarded, it throws this system exception to container.

Redelivery depends on the above discussion.

4. onMessage itself throws ApplicationException???
Result : ???

Reading from some other post
http://www.coderanch.com/t/465589/java-EJB-SCBCD/certification/Application-Exception-MDB

"As per section 5.4.17 of EJB 3.0 Core specification, a message-driven bean’s message listener method must not throw the java.rmi.RemoteException. It can throw any other exception. If it throws an application exception marked with rollback, the transaction (if any) is rolled back, the exception is rethrown to the resource adapter, and the bean is NOT discarded. If it throws a system exception, the exception is logged, the transaction (if any) is rolledback, and the bean is discarded. "


5. i set context.setRollBackOnly explicitliy on onMessage method with required attribute.
Result : ???

Since MDB has been marked for rollback, the transaction will be rollback and message will be redelivered.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB Message Redelivery and discard