Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about MDB behavior

 
Deep Chand
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is my understanding @ MDB (message driven bean). Please correct me if I'm wrong.

With CMT, the acknowledgement is always sent back to the JMS when the method ends successfully i.e. transaction is committed. As the onMessage() can not throw a checked (application) exception, it can only throw a system exception, which implies that if an exception is thrown from an onMessage() method, the transaction will roll back and no acknowledgement is sent back.

With BMT, the acknowledgement is always sent back when the bean provider commits/rollback the transaction explicitly. However, the acknowledgement is ALWAYS sent irrespective of whether the tx is COMMITTED or ROLLED BACK.

Now one doubt:
What will happen if the BMT MDB throws a system exception from onMessage() method?

Please reply.

Thanks
Deep
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen if the BMT MDB throws a system exception from onMessage() method?


I guess nothing will happen excitingly other than your MDB gets killed.

As you mentioned "With BMT, the acknowledgement is always sent", this is because the default acknowedge-mode for BMT MDB is AUTO_ACKNOWLEDGE. Actually, it does not support other modes like CLIENT_ACKNOWLEDGE. So once the message has been delievered successfully, the acknowledgement is sent regardless of the transaction will be committed/rolled back and your MDB is still alive or dead.
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen if the BMT MDB throws a system exception from onMessage() method?


I guess nothing will happen excitingly other than your MDB gets killed.

As you mentioned "With BMT, the acknowledgement is always sent", this is because the default acknowedge-mode for BMT MDB is AUTO_ACKNOWLEDGE. Actually, it does not support other modes like CLIENT_ACKNOWLEDGE. So once the message has been delievered successfully, the acknowledgement is sent regardless of the transaction will be committed/rolled back and your MDB is still alive or dead.
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deep

There are two parts to the answer to this question.

1) If a BMT MDB throws a RuntimeException then container log the message, mark the tx for rollback and discard the instance.

2) As far as message acknowledgement is concerned:

If a BMT MDB throws a RuntimeException, the container should not acknowledge the message. From the client perspective, the message consumer continues to exist. If the client continues sending messages to the destination or endpoint associated with the bean, the container can delegate the client´┐Żs messages to another instance.

Thanks

-- Ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic