簡體   English   中英

使用Open MQ時的Spring JMS會話問題

[英]Spring JMS Session Issue When Using Open MQ

我正在使用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

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> 

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>

根據ConnectionAdapter源代碼OpenMQ郵件列表上的此存檔線程,Spring或您的代碼本身在單個JMS Connection上創建多個會話。

可以通過將系統屬性imq.jmsra.inACC設置為false來禁用此OpenMQ行為(引發錯誤),但不能令人滿意。

沒有事務管理器,Spring使用org.springframework.jms.connection.SingleConnectionFactory為多個使用者共享一個連接。

您應該將DefaultMessageListenerContainer cacheLevelName屬性設置為CACHE_NONE以便每個使用者線程在單個連接上獲得自己的會話。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM