MDB->Session Bean -> JMS - Transaction question

Discussions

EJB programming & troubleshooting: MDB->Session Bean -> JMS - Transaction question

  1. We are using Tibco JMS and Weblogic 7.0.

    We have a MDB that takes message and calls
    a stateless session bean which does business processing,
    ( oracle database to be included in transaction later)
    and publishes on JMS for downstream process.

    We desire all these operations in one transaction.

    Please comment/advise on the following settings:
    1. XATopicConnectionFactory is created in tibjms server.

    2. In the MDB, set it as container managed with
       transaction attribute as Required.
       Call the session bean. When any exceptions are
       caught invoke mdbContext.setRollBackOnly().
       
    3. Session bean has container managed transaction
       with Required attribute. Shoud it use
       javax.jms.XAConnection and XAConnectionFactory or the
       regular Connection,ConnectionFactory and Session
       classes to lookup the connectionFactory to publish to
       the downstream process?

    4. In the javax.jms.Session/XASession - I guess we should
       be setting the transacted option to be false.
       topicConnection.createTopicSession(false,AUTO_ACK..);

    I am bit confused as to how to link the MDB transaction
    with the session bean transaction with the JMS publisher
    and ultimately the database process.

    Thanks in advance for your insights and help,

    Venkat
  2. From the EJB 2.0 specification: "An onMessage call is always a separate transaction, because there is never a transaction in progress when the method is called."
    When a message arrives, it is passed to the Message Driven Bean through the onMessage() method, that is where the business logic goes.
    Since there is no guarantee when the method is called and when the message will be processed, is the container that is responsible of managing the environment, including transactions.
  3. The J2EE 1.3 Spec says that a JMS transaction with an XA resource adaptor and an JDBC XA driver can be commited or rollback within the same transaction.

    Obviously, when the mdb is called, this is done in a non transactional context, but in his (optionally) new transaction context so calls to other beans can participate.