1

我正在使用 spring-jms-3.0.6.RELEASE 并打开 MQ。关于为什么会引发以下异常的任何想法?

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

网页.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> 

testlistener-context-api.xml:

<?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>

testmsg-context-api.xml:

<?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>
4

1 回答 1

1

根据OpenMQ 邮件列表上的ConnectionAdapter 源代码和此存档线程,Spring 或您的代码本身在单个 JMS 连接上创建了多个会话。

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

如果没有事务管理器,Spring 使用org.springframework.jms.connection.SingleConnectionFactory为多个消费者共享单个连接。

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

于 2012-05-09T20:51:07.033 回答