5

我有一个 JBoss Seam 2.3 应用程序正在尝试将事件写入 JBoss AS 7.1 上的 JMS 队列。写入发生在无状态 EJB 中,并使用标准 Seam 注入机制。代码看起来像这样(不是确切的代码片段。只是显示我正在做的事情的类型):

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

   ...

   @In
   private QueueSession queueSession;

   @In
   private QueueSender myQueueSender;

   ...


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

但是,我注意到当应用程序处于负载状态并且经常调用此方法时,我在日志中收到以下异常:

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]

将请求发送到 RESTful 服务后,最终会调用 foo() 方法。客户端可能会连续多次调用此服务,但它们都是不同的调用。

知道什么会导致此异常吗?我过去成功地使用了 Seam 和 JMS,没有任何问题,但是这个应用程序对 JMS 队列的写入比我过去编写的要多得多。我的 components.xml 文件是 seutp 正确,我没有得到任何错误。此外,我对 foo() 进行一次调用并将消息写入队列没有问题。只有当我对 foo() 方法进行大量顺序调用时才会发生这种情况。

想法?对于我可以尝试的事情或解决此问题的方法有什么建议吗?

更新: 我应该提到我使用的消息队列是嵌入在 JBoss AS 7.1 中的 HornetQ。在我看来,这似乎是围绕多个线程尝试将消息写入队列的某种问题。除此之外,我没有任何信息,也不知道如何解决这个问题。我真的很感激你能提供的任何帮助。

4

1 回答 1

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.

于 2013-02-05T15:34:17.597 回答