How to separate business- and infrastructure exceptions in MDBs
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jonas_Carlsson
Posted On:   Friday, February 14, 2003 10:45 AM

Hi, I've run into a problem that must be fairly common and I'm curious for best practices. My MDB (using a container managed transaction) receives an update message, forwards it to a session bean (also container managed and participating in same transaction) who interprets it and updates a database. Roughly three scenarios are possible: 1) Everything works fine. The complete transaction should commit and thus database changes happen and the message removed from the queue. 2) Some non-business reason prevents completing something. The complete transaction should rollback and thus no changes commited to the database and the message should go back on the    More>>

Hi,



I've run into a problem that must be fairly common and I'm curious for best practices.



My MDB (using a container managed transaction) receives an update message, forwards it to a session bean (also container managed and participating in same transaction) who interprets it and updates a database.



Roughly three scenarios are possible:



1) Everything works fine. The complete transaction should commit and thus database changes happen and the message removed from the queue.



2) Some non-business reason prevents completing something. The complete transaction should rollback and thus no changes commited to the database and the message should go back on the queue for future redelivery



3) After performing parts of the database updates, it is discovered that the parts of the message is rotten and the updates cannot be completed. At this time, the database should be rollbacked, but I do not want the message to go back on the queue since it would create a "poison message".



#1 and #2 are fine, but #3 is causing me a problem since the transaction must either rollback or commit. The solution I'm thinking of is to change the session bean transaction configuration from required to requires new, so that it starts a transaction of its own. This way, I can catch a business error in the session bean, set the session bean/database transaction to rollback and then exit normally. The calling MDB doesnt realise something is wrong and commits its transaction so that the message is not put back on the queue.



Would this work? Is there a better solution?





BR



Jonas Carlsson

   <<Less

Re: How to separate business- and infrastructure exceptions in MDBs

Posted By:   Nick_Maiorano  
Posted On:   Wednesday, February 19, 2003 07:26 PM

Jonas,



Your proposed solution is good. However, you may want to consider declaring your MDB with a "NotSupported" transaction so that you only start 1 transaction rather than 2. Your transaction would only start in your session bean. The only problem is that your case #2 will end flushing the message from the main queue thereby preventing future re-delivery. If this is acceptable for your requirements, you will have better performance because of the reduction in transactions.

About | Sitemap | Contact