4 Replies Latest reply on Dec 23, 2003 5:58 AM by Adrian Brock

    Using transacted TopicSessions in Session Beans

    Rudi Vankeirsbilck Newbie

      Hi all,

      To publish events on a JMS topic, I am using a session bean (which happens to be compliant with Sun's guidelines in the tutorial on JMS).
      In the session beans business method, I am getting a TopicConnection, a transacted TopicSession, the Topic and a TopicPublisher. The event then gets published on the Topic and I then release the resources I have acquired (using the close method on both TopicSession and TopicConnection). No problems there at first.
      However, I have discovered that closing a TopicSession will rollback any transactions resulting of course in the event not being delivered to the subscribers. This is actually described in the javadoc so this is expected behavior.

      On the other hand, section 17.3.5 of the ejb 2.1 specification states that: "the container manages the transactional enlistment of session on behalf of the bean,..."

      Does the latter also mean that the container will release these resources after they have been committed?

        • 1. Re: Using transacted TopicSessions in Session Beans
          Adrian Brock Master

          I've answered this in the sticky FAQ topic


          • 2. Re: Using transacted TopicSessions in Session Beans
            Rudi Vankeirsbilck Newbie

            Thanks, I really needed that.

            The Sticky FAQ does not answer the part of the question if I need to close the TopicConnection and TopicSession myself or if the container will do that if my session bean is container managed.

            I would prefer to work with container managed beans since I actually have two session beans that will publish messages and I would like both of them to work in the same transaction. If however, I need to do bean managed transactions to be able to close the jms resources then both beans will start their own UserTransaction...


            • 3. Re: Using transacted TopicSessions in Session Beans
              Rudi Vankeirsbilck Newbie

              I will need some more help please.

              Now that I am using java:/JmsXA I am getting the following exception when getting a TopicSession:

              11:13:59,400 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jms.JmsSession@63b5ed
              java.lang.Exception: STACKTRACE
              at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:282)
              at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:506)
              at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:814)
              at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.createTopicSession(JmsSessionFactoryImpl.java:159)
              at com.bluespace.core.implementation.jms.JMSFacadeDefaultImplementation.createTopicSession(JMSFacadeDefaultImplementation.java:20)
              at com.bluespace.core.implementation.jms.JMSFacadeDefaultImplementation.getTopicResources(JMSFacadeDefaultImplementation.java:37)
              at com.bluespace.core.implementation.events.publishers.abstracts.BlueSpacePublisher.acquireResources(BlueSpacePublisher.java:168)
              at com.bluespace.core.implementation.events.publishers.abstracts.BlueSpacePublisher.publish(BlueSpacePublisher.java:207)

              The code I am using to do this is:

              TopicConnection connection = (TopicConnectionFactory) initialContext.lookup("java:/JmsXA");
              TopicSession session = connection.createTopicSession(true, TopicSession.SESSION_TRANSACTED);

              Why is it closing the connection I just created?


              • 4. Re: Using transacted TopicSessions in Session Beans
                Adrian Brock Master

                The sessions are pooled behind the scenes. It is like the jdbc connection pool.
                You should do the same close to return it to the pool:

                // Use resources