4 Replies Latest reply on Oct 22, 2011 9:28 AM by balaalwayz.balamurugan1.c.tcs.com

    ManagedTopicPublisher - javax.jms.IllegalStateException: Only allowed one session per connection.

    jgilbert

      Has anyone seen this error?


      14:33:46,437 ERROR [JmsSessionFactoryImpl] could not create session
      javax.jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6
              at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.allocateConnection(JmsSessionFactoryImpl.java:380)
              at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.createTopicSession(JmsSessionFactoryImpl.java:167)
              at org.jboss.seam.jms.TopicSession.create(TopicSession.java:38)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:138)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2201)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2124)
              at org.jboss.seam.Component.newInstance(Component.java:2084)
              at org.jboss.seam.Component.getInstance(Component.java:1978)
              at org.jboss.seam.Component.getInstance(Component.java:1940)
              at org.jboss.seam.Component.getInstance(Component.java:1934)
              at org.jboss.seam.Component.getInstance(Component.java:1914)
              at org.jboss.seam.Component.getInstance(Component.java:1909)
              at org.jboss.seam.jms.TopicSession.instance(TopicSession.java:55)
              at org.jboss.seam.jms.ManagedTopicPublisher.create(ManagedTopicPublisher.java:53)
      



      It appears to be related to this configuration in the jms-ra.rar:


            <outbound-resourceadapter>
               <connection-definition>
                  <managedconnectionfactory-class>org.jboss.resource.adapter.jms.JmsManagedConnectionFactory</managedconnectionfactory-class>
      
      ...
      
                  <config-property>
                    <config-property-name>Strict</config-property-name>
                      <config-property-type>java.lang.Boolean</config-property-type>
                      <config-property-value>true</config-property-value>
                  </config-property>
      




      Basically, I have an MDB on a queue that will publish zero or more messages to a topic.
      This is ok because all the messages are published in the same event scope. However, there can be more than 1 instance of the MDB pulling messages off the queue, which means there are concurrent event scopes creating sessions off the single application scoped topic connection, which is when the exception occurs.


      It looks like there are 3 options:



      1. change the jms-ra.rar setting. probably not a good idea...

      2. limit my MDB to a pool of 1. bad for throughput performance...

      3. make the topic connection event scoped as well. not great for performance either...




      No. 3 is probably the safest option. What has anyone else done?

        • 1. Re: ManagedTopicPublisher - javax.jms.IllegalStateException: Only allowed one session per connection.
          jgilbert

          So far my tests with option 3 are working. This is probably a bug and the connection components should default to event scope.


          I will create a jira ticket if anyone else agrees this is a bug.

          • 2. Re: ManagedTopicPublisher - javax.jms.IllegalStateException: Only allowed one session per connection.
            I'm getting the same error, but I'm not understanding exactly what you mean with #3 - I'm fairly new to JMS.  We have a Stateless bean that's being called indirectly by an MDB as a response to a message, that's trying to publish a notification on a topic.  Using HornetQ, but I don't think that's relevant to the situation.  Any suggestions as to how to resolve this?

            We're using Seam 2.2.0.GA
            • 3. Re: ManagedTopicPublisher - javax.jms.IllegalStateException: Only allowed one session per connection.
              jgilbert

              To implement #3 we over wrote the component. Note:



              1. event scope

              2. precedence

              3. extends original class

              4. connection just closed, not stopped



              @Scope(ScopeType.EVENT)
              @BypassInterceptors
              @Name("org.jboss.seam.jms.topicConnection")
              @Install(precedence = APPLICATION, genericDependencies = org.jboss.seam.jms.ManagedTopicPublisher.class)
              public class TopicConnection extends org.jboss.seam.jms.TopicConnection {
                   private javax.jms.TopicConnection topicConnection;
              
                   @Create
                   public void init() throws NamingException, JMSException {
                        topicConnection = getTopicConnectionFactory().createTopicConnection();
                        topicConnection.start();
                   }
              
                   @Destroy
                   public void destroy() throws JMSException {
                        // topicConnection.stop();
                        topicConnection.close();
                   }
              
                   private TopicConnectionFactory getTopicConnectionFactory()
                             throws NamingException {
                        return (TopicConnectionFactory) Naming.getInitialContext().lookup(
                                  getTopicConnectionFactoryJndiName());
                   }
              
                   @Unwrap
                   public javax.jms.TopicConnection getTopicConnection() {
                        return topicConnection;
                   }
              }
              



              • 4. Re: ManagedTopicPublisher - javax.jms.IllegalStateException: Only allowed one session per connection.
                balaalwayz.balamurugan1.c.tcs.com

                Hi John Gilber,
                The first option works for me. But since it is not a good idea, i'm not forcing myself to use that option.
                I would like to use the option 3.
                But here the problem for me is the javax.jms.QueueSession. I'm not using topic connection.
                Is there any way to avoid this problem in queuesession?


                Your help is much appreciated!!!
                Thanks in advance,
                Bala