使用Open MQ时出现Spring JMS会话问题

使用Open MQ时出现Spring JMS会话问题,spring,jms,spring-jms,openmq,Spring,Jms,Spring Jms,Openmq,我正在使用spring-jms-3.0.6.RELEASE和openmq。关于为什么会提出以下例外情况,你有什么想法吗 2012-05-02 17:56:18,420 [stuJmsContainer-803059] WARN org.springframework.jms.listener.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'TestQ

我正在使用spring-jms-3.0.6.RELEASE和openmq。关于为什么会提出以下例外情况,你有什么想法吗

2012-05-02 17:56:18,420 [stuJmsContainer-803059] WARN
org.springframework.jms.listener.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 

'TestQ' - trying to recover. Cause: 
MQRA:CA:createSession failed-Only one JMS Session allowed when managed connection is involved in a transaction
web.xml:

    <context-param>
            <param-name>contextConfigLocation</param-name>
             <param-value>
                    classpath:/spring/testlistener-context-api.xml
                    classpath:/spring/testmsg-context-api.xml
             </param-value>
        </context-param>
 <listener>
      <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
 </listener>
 <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener> 
 <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener> 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <tx:annotation-driven />

    <bean id="testListener" class="com.test.TestListener" />

    <bean id="executionInterceptor" class="com.test.ExecutionInterceptor" />

     <bean id="testJmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
        <property name="destinationName" value="TestQ"/>
        <property name="sessionTransacted" value="false"/>
        <property name="messageListener" ref="stuMessageListener" />
        <property name="concurrentConsumers" value="5" />
        <property name="maxConcurrentConsumers" value="100" />
        <property name="receiveTimeout" value="30000" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"/>

    <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.qconnectionfactory}">

        </property>
    </bean>
    <bean id="jmsTopicConnectionFactory"  class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.tconnectionfactory}">

        </property>
    </bean>
    <bean id="myJMSConnectionFactory" class="com.test.OpenMqConnectionFactoryBean">
        <property name="imqAddressList" value="${jms.imq.url}" />
        <property name="imqDefaultUsername" value="${jms.imq.user}" />
        <property name="imqDefaultPassword" value="${jms.imq.password}" />
        <property name="imqHost" value="${jms.imq.host}" />
        <property name="imqPort" value="${jms.imq.port}" />
    </bean>
    <bean id="jmsTopicTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsTopicConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.tconnectionfactory}"/>
        <property name="pubSubDomain" value="true" />
    </bean>
    <bean id="jmsTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.qconnectionfactory}"/>
    </bean>

    <tx:annotation-driven />
</beans>

上下文配置位置
类路径:/spring/testlistener-context-api.xml
类路径:/spring/testmsg-context-api.xml
org.jboss.resteasy.plugins.spring.SpringContextLoaderListener
org.springframework.web.util.Log4jConfigListener
org.springframework.web.context.request.RequestContextListener
testlistener上下文api.xml:

    <context-param>
            <param-name>contextConfigLocation</param-name>
             <param-value>
                    classpath:/spring/testlistener-context-api.xml
                    classpath:/spring/testmsg-context-api.xml
             </param-value>
        </context-param>
 <listener>
      <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
 </listener>
 <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener> 
 <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener> 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <tx:annotation-driven />

    <bean id="testListener" class="com.test.TestListener" />

    <bean id="executionInterceptor" class="com.test.ExecutionInterceptor" />

     <bean id="testJmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
        <property name="destinationName" value="TestQ"/>
        <property name="sessionTransacted" value="false"/>
        <property name="messageListener" ref="stuMessageListener" />
        <property name="concurrentConsumers" value="5" />
        <property name="maxConcurrentConsumers" value="100" />
        <property name="receiveTimeout" value="30000" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"/>

    <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.qconnectionfactory}">

        </property>
    </bean>
    <bean id="jmsTopicConnectionFactory"  class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.tconnectionfactory}">

        </property>
    </bean>
    <bean id="myJMSConnectionFactory" class="com.test.OpenMqConnectionFactoryBean">
        <property name="imqAddressList" value="${jms.imq.url}" />
        <property name="imqDefaultUsername" value="${jms.imq.user}" />
        <property name="imqDefaultPassword" value="${jms.imq.password}" />
        <property name="imqHost" value="${jms.imq.host}" />
        <property name="imqPort" value="${jms.imq.port}" />
    </bean>
    <bean id="jmsTopicTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsTopicConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.tconnectionfactory}"/>
        <property name="pubSubDomain" value="true" />
    </bean>
    <bean id="jmsTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.qconnectionfactory}"/>
    </bean>

    <tx:annotation-driven />
</beans>

testmsg上下文api.xml:

    <context-param>
            <param-name>contextConfigLocation</param-name>
             <param-value>
                    classpath:/spring/testlistener-context-api.xml
                    classpath:/spring/testmsg-context-api.xml
             </param-value>
        </context-param>
 <listener>
      <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
 </listener>
 <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener> 
 <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener> 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <tx:annotation-driven />

    <bean id="testListener" class="com.test.TestListener" />

    <bean id="executionInterceptor" class="com.test.ExecutionInterceptor" />

     <bean id="testJmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
        <property name="destinationName" value="TestQ"/>
        <property name="sessionTransacted" value="false"/>
        <property name="messageListener" ref="stuMessageListener" />
        <property name="concurrentConsumers" value="5" />
        <property name="maxConcurrentConsumers" value="100" />
        <property name="receiveTimeout" value="30000" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"/>

    <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.qconnectionfactory}">

        </property>
    </bean>
    <bean id="jmsTopicConnectionFactory"  class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName" value="${jms.jndi.tconnectionfactory}">

        </property>
    </bean>
    <bean id="myJMSConnectionFactory" class="com.test.OpenMqConnectionFactoryBean">
        <property name="imqAddressList" value="${jms.imq.url}" />
        <property name="imqDefaultUsername" value="${jms.imq.user}" />
        <property name="imqDefaultPassword" value="${jms.imq.password}" />
        <property name="imqHost" value="${jms.imq.host}" />
        <property name="imqPort" value="${jms.imq.port}" />
    </bean>
    <bean id="jmsTopicTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsTopicConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.tconnectionfactory}"/>
        <property name="pubSubDomain" value="true" />
    </bean>
    <bean id="jmsTemplate"  class="com.test.CustomJMSTemplate">
        <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
        <property name="connectionFactoryName" value="${jms.jndi.qconnectionfactory}"/>
    </bean>

    <tx:annotation-driven />
</beans>

根据上的和此存档线程,Spring或您的代码本身在单个JMS连接上创建多个会话

可以通过将系统属性
imq.jmsra.inACC
设置为
false
来禁用此OpenMQ行为(引发错误),但这并不令人满意

在没有事务管理器的情况下,Spring用于为多个使用者共享单个连接

您应该将属性设置为
CACHE\u NONE
,以便每个使用者线程在单个连接上获得自己的会话。

根据和上的此存档线程,Spring或您的代码本身在单个JMS连接上创建多个会话

可以通过将系统属性
imq.jmsra.inACC
设置为
false
来禁用此OpenMQ行为(引发错误),但这并不令人满意

在没有事务管理器的情况下,Spring用于为多个使用者共享单个连接


您应该将属性设置为
CACHE_NONE
,以便每个使用者线程在单个连接上获得自己的会话。

您可以提供您的JmsContainer配置吗?@Nicholas-添加了我的Spring JMS配置,这就是您要找的吗?您可以提供您的JmsContainer配置吗?@Nicholas-添加了我的Spring JMS配置,这就是你想要的吗?谢谢你的回复,似乎解决了这个问题。只是想澄清一下,,cacheLevelName没有使用默认值CACHE_NONE,因为我没有使用事务管理器?是的,完全正确:交换到CACHE_NONE并为每个线程提供自己的线程现在会导致另一个异常:WARN org.springframework.jms.listener.DefaultMessageListenerContainer-目标“TestQ”的jms消息侦听器调用程序设置失败-试图恢复。原因:MQRA:CFA:分配失败:createConnection:分配连接时出错。原因:正在使用的连接等于最大池大小和过期的最大等待时间。无法分配更多连接。有什么想法吗?我使用默认的连接池大小10(最小)32(最大),最大等待时间为60秒。尝试将最大等待时间降低到30秒我猜错了:您最多配置100个最大并发使用者。如果使用CACHE_NONE,则意味着每个会话最多可以有100个JMS连接。因此,您的连接池太小。顺便说一下,Spring文档确实建议使用事务管理器!感谢您的回复,似乎解决了这个问题。只是想澄清一下,,cacheLevelName没有使用默认值CACHE_NONE,因为我没有使用事务管理器?是的,完全正确:交换到CACHE_NONE并为每个线程提供自己的线程现在会导致另一个异常:WARN org.springframework.jms.listener.DefaultMessageListenerContainer-目标“TestQ”的jms消息侦听器调用程序设置失败-试图恢复。原因:MQRA:CFA:分配失败:createConnection:分配连接时出错。原因:正在使用的连接等于最大池大小和过期的最大等待时间。无法分配更多连接。有什么想法吗?我使用默认的连接池大小10(最小)32(最大),最大等待时间为60秒。尝试将最大等待时间降低到30秒我猜错了:您最多配置100个最大并发使用者。如果使用CACHE_NONE,则意味着每个会话最多可以有100个JMS连接。因此,您的连接池太小。顺便说一下,Spring文档确实建议使用事务管理器!