Thursday, September 24, 2009

MDB Transaction Management & Acknowledge-Mode

"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." CMT Acknowledge mode (Ref:EJB specs 2.0, section 15.4.8)

In JMS when you use distributed transactions (i.e. CMT) you cannot set the delivery mode, the message is acknowledged when the transaction commits successfully. That's why you shouldn't set acknowledge mode when using CMT.

When you use BMT the message is acknowledged when you return normally from the onMessage() method, i.e. that you do not throw a RuntimeException from inside the onMessage method. The difference between Auto-acknowledge and Dups-ok-acknowledge is that with Auto-acknowledge the bean provider is guaranteed that the message is only delivered once-and-only-once with Dups-ok-acknowledge you do not have that guarantee, and the bean provider should write could that can handle that the same message is delivered more than once. Dups-ok-acknowledge is supposed to be more performance efficient than Auto-acknowledge.

Best Practices for MDBs
  • The following approaches and suggestions should be used during the development and deployment of MDBs:
  • Consider using a session bean method for implementing and calling from onMesage()when business logic is complex.
  • Avoid associating more than one MDB with the same JMS queue, because JMS does not define how messages are distributed between the queue receivers.
  • Specify durability when using a topic with your MDB.
  • If you want your MDB to be transactional, specify the transaction attribute to be Required . Only Required and NotSupported are allowed for container-managed transactions in MDB.
  • Use the MessageSelector to filter out unwanted messages, leading to performance improvement.
  • Specify acknowledgeMode when you use bean-managed transactions for your MDB. If you select Dups-ok-acknowledge, your MDBs must be able to handle duplicate messages correctly.
  • When deciding on which flavor of connection-factories to use for lookup, you should use XA connection factories if your application components need to participate in a global transaction. Otherwise, use non-XA connection factories for better performance.
  • To enable parallel processing of messages, define a value for activation-config-property named receiverThreads under the section where other properties are defined in ejb-jar.xml, e.g.:
Important Points
  • Only REQUIRED or NOT_SUPPORTED transaction attributes are supported by the MBD.
  • To deal with the poison messages, use delivery count and a dead message queue.
  • MDB Callback methods are PostConstruct() and Predestroy()

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home