使用Open MQ时的Spring JMS会话问题 [英] Spring JMS Session Issue When Using Open MQ

查看:111
本文介绍了使用Open MQ时的Spring JMS会话问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring-jms-3.0.6.RELEASE并打开MQ.为什么会提出以下例外情况的任何想法?

I'm using spring-jms-3.0.6.RELEASE and open MQ. Any ideas on why the below exception would be raise?

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连接上创建多个会话.

According to the ConnectionAdapter source code and this archive thread on OpenMQ mailing list, either Spring or your code itself creates more than one session on a single JMS Connection.

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

This OpenMQ behavior (raise an error) can be disabled by setting the system property imq.jmsra.inACC to false but it is not satisfying.

在没有事务管理器的情况下,Spring使用

Without transaction manager, Spring uses org.springframework.jms.connection.SingleConnectionFactory to share a single connection for multiple consumers.

您应该设置

You should set DefaultMessageListenerContainer cacheLevelName property to CACHE_NONE so that each consumer thread gets its own session on a single connection.

这篇关于使用Open MQ时的Spring JMS会话问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆