5

I have a JBoss Seam 2.3 application that is trying to write events to a JMS queue on JBoss AS 7.1. The writes are occurring within a stateless EJB, and use the standard Seam injection mechanism. The code looks something like this (not an exact code snippet. Just shows the type of thing I'm doing):

@Name("myEjb")
@Stateless
public class MyEjb {

   ...

   @In
   private QueueSession queueSession;

   @In
   private QueueSender myQueueSender;

   ...


   public foo() {
       ...
       // Code to place a TextMessage on the queue
       ...
   }
}

However, I'm noticing that when the application is under load and this method is being called a lot, I get the following exception in the logs:

21:58:57,800 ERROR [org.hornetq.ra.HornetQRASessionFactoryImpl] (http--0.0.0.0-8080-1) 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.hornetq.ra.HornetQRASessionFactoryImpl.allocateConnection(HornetQRASessionFactoryImpl.java:816)

at org.hornetq.ra.HornetQRASessionFactoryImpl.createQueueSession(HornetQRASessionFactoryImpl.java:237)

at org.jboss.seam.jms.QueueSession.create(QueueSession.java:38) [jboss-seam.jar:2.3.0.Final]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]

at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]

at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.callComponentMethod(Component.java:2313) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.callCreateMethod(Component.java:2236) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.newInstance(Component.java:2196) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.getInstance(Component.java:2034) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.getInstance(Component.java:1996) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:60) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2427) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.getValueToInject(Component.java:2366) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.injectAttributes(Component.java:1743) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.Component.inject(Component.java:1561) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.0.Final]

at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.3.0.Final]

The foo() method is eventually being called after a request is sent to a RESTful service. The client could potentially make a number of calls to this service in a row, but they are all distinct calls.

Any idea what would be causing this Exception? I've successfully used Seam and JMS in the past with no problem, but this application makes considerably more writes to the JMS queue than the ones I've written in the past. My components.xml file is seutp correctly and I don't get any errors there. Additionally, I have no problem making a single call to foo() and writing a message to the queue. It only happens if I make a large number of sequential calls to the foo() method.

Thoughts? Any recommendations for things I can try or ways to troubleshoot this?

UPDATE: I should mention that the messaging queue I am using is HornetQ embedded within JBoss AS 7.1. It seems to me to be some sort of issue around multiple threads trying to write messages to the queue. I don't have any info beyond that, or any idea how to go about getting past this issue. I would REALLY appreciate any help you can give.

Shadowman
  • 11,150
  • 19
  • 100
  • 198

1 Answers1

3

That's part of the JCA specification. when you a pooled connection factory, you can't create more than one session, since the JCA connections internally are a tupple of connection / session.

JCA Connections will give you a pool and seamless integration with XA. If you don't need XA, you could just use the regular connection factories defined in your standalone.xml.

if you do need pool and XA, create one connection per session and you should be over this issue.

Clebert Suconic
  • 5,353
  • 2
  • 22
  • 35
  • So what change would I need to make to accomplish this? Is this something in the JBoss configuration I need to change? What about in my Seam components.xml file? – Shadowman Feb 05 '13 at 17:38
  • Firs things: you need to make sure you are not leaking the connection. close your connections and sessions... I don't have much material to look at.. I would need to see more from your application. I can't answer for the seam config, but if you provide me a runnable example I can take a look. – Clebert Suconic Feb 05 '13 at 20:33
  • It could be a bug on Seam... if you provide more code for your sample I could then figure out... if you want to you could add a running sample to hornetq's forum and I could come back here and give you the definitive answer. – Clebert Suconic Feb 06 '13 at 05:16
  • Also -- just so I can learn a bit more about this -- when would I want XA versus non-XA? Is there a use case that would require one over the other? – Shadowman Feb 07 '13 at 14:11
  • This is more about Pooled versus non-pooled. When using a pooled connection factory you get integration with XA. That means if you receive a message and insert a record on the database, the Transaction manager will guarantee both branches are either committed or rolledback in such way you won't have data created from nothing. – Clebert Suconic Feb 07 '13 at 15:58