What are the different strategies for deploying an MDB
There are four different strategies depending upon what you are trying to achieve.
CMT with
Required
- when you want the message redelivered if the MDB transaction rollsback.
CMT with
NotSupported
- when you don't want the work done in the MDB to force a rollback.
BMT - which is similar to CMT/
NotSupported
except you use UserTransactions to start the isolated transaction
Non XAConnectionFactory when your JMS provider does not support XA
CMT and Required
This is achieved with the following in ejb-jar.xml
<ejb-jar> <enterprise-beans> <message-driven> <ejb-name>MessageBean</ejb-name> <ejb-class>org.acme.MessageBean</ejb-class> <message-selector></message-selector> <transaction-type>Container</transaction-type> <!-- CMT --> <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> <subscription-durability>NonDurable</subscription-durability> </message-driven-destination> </message-driven> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>MessageBean</ejb-name> <method-name>onMessage</method-name> <method-params> <method-param>javax.jms.Message</method-param> </method-params> </method> <!-- REQUIRED --> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar>
CMT and NotSupported
This is achieved with the following in ejb-jar.xml
<ejb-jar> <enterprise-beans> <message-driven> <ejb-name>MessageBean</ejb-name> <ejb-class>org.acme.MessageBean</ejb-class> <message-selector></message-selector> <transaction-type>Container</transaction-type> <!-- CMT --> <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> <subscription-durability>NonDurable</subscription-durability> </message-driven-destination> </message-driven> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>MessageBean</ejb-name> <method-name>onMessage</method-name> <method-params> <method-param>javax.jms.Message</method-param> </method-params> </method> <!-- NOT SUPPORTED --> <trans-attribute>NotSupported</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar>
BMT - User Transactions
This is achieved with the following in ejb-jar.xml
<ejb-jar> <enterprise-beans> <message-driven> <ejb-name>MessageBean</ejb-name> <ejb-class>org.acme.MessageBean</ejb-class> <message-selector></message-selector> <transaction-type>Bean</transaction-type> <!-- BMT --> <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> <subscription-durability>NonDurable</subscription-durability> </message-driven-destination> </message-driven> </enterprise-beans> </ejb-jar>
Non XAConnectionFactory
This is configured on the JMS provider.
The rules are the same as the above, except the CMT with
Required
is less reliable than when two phase commit can be used.
Related
Exception handling and Transaction Rollback
Comments