Hi everyone,
I have discovered a discrepancy regarding message
acknowledgement using BMT message driven beans. On page 458 HF book,
it says:
"If the method throws a runtime exception, the message goes back on the queue"
According to the spec, it says:
"Message-driven beans should not attempt to use the JMS API for
message acknowledgment. Message acknowledgment is automatically
handled by the container. If the message-driven bean uses container
managed transaction demarcation, message acknowledgment is handled
automatically as a part of the transaction commit. If bean managed
transaction demarcation is used, the message receipt cannot be part of
the bean-managed transaction, and, in this case, the receipt is
acknowledged by the container."
..and according to Simon Brown's interpretation of the spec on
http://weblogs.java.net/blog/simongbrown/archive/2004/06/message_acknowl.html, it says:
"So then, message acknowledgment is handled by the container. With
CMT, a commit or rollback will effectively acknowledge or not
acknowledge the message, but with BMT the message will always be
acknowledged. This is a subtle point but means with BMT that if the
onMessage() doesn't return successfully, the message gets acknowledged
anyway and redelivery won't occur. It seems that you have to be very
careful about implementing BMT message-driven beans!"
The Ejbplus exam simulator also backs this argument in one of the exam question anwsers.
"Since the onMessage() throws a systems exception each time it gets a message, it causes an infinite loop of delivering the message. Many application servers provide support for handing this kind of situation but if not checked, it can potentially bring down the appserver.
Also, rolling back the transaction is same as throwing a system exception because the message receipt will not be acknowledged.
Also remember that this happens only in the case of CMTs (not not for BMTs) because in case of a CMT MDB, the message acknowledgement is a part of the transaction (which gets rolled back) while in case of a BMT MDB, it is not. So even if a BMT MDB throws a system exception, the message is acknowledged.
"
Can anyone help clarify this discrepancy?
Thanks,
Sati
[ December 31, 2004: Message edited by: Sati Sidhu ]
[ December 31, 2004: Message edited by: Sati Sidhu ]
[ December 31, 2004: Message edited by: Sati Sidhu ]
[ January 01, 2005: Message edited by: Sati Sidhu ]