当前位置: 首页 > 知识库问答 >
问题:

使用Open MQ时的Spring JMS会话问题

西门鹏程
2023-03-14

我正在使用spring-jms-3.0.6.RELEASE和open 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>

共有1个答案

谭勇
2023-03-14

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

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

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

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

 类似资料:
  • 我正在Codeigniter中创建API。在这个API中,我为用户提供了一个登录函数。如果登录成功,我将在CI会话中设置用户数据,并将会话返回给用户。 现在,用户可以使用该会话ID来验证他自己的所有其他请求,如添加/更新/删除。基本上,我希望当用户发送下一个请求时,我可以根据他的会话ID验证他的凭据。 客户请求代码: 上面是一个从客户端到服务器的登录请求示例。在服务器端,服务器验证客户端提供的凭据

  • 大家好,我对我的应用程序使用哪个会话bean感到困惑。我正在尝试构建一个像Facebook这样的移动网络应用程序,它可以同时允许多个用户。我上网冲浪以获取更多信息。从我从stack overflow和其他教程中收集到的信息来看,有状态会话bean维护事务内部和事务之间的状态(会话状态),并且它是针对客户端的。无状态不支持,但支持多个客户机来共享bean实例。而Singleton有点类似于无状态be

  • 我错过了什么?

  • 我试图使用Spring Cloud的Zuul、Eureka和我自己的服务实现微服务架构。我有多个具有UI和服务的服务,每个服务都可以使用x509安全性对用户进行身份验证。现在我想把祖尔放在那些服务机构的前面。由于Zuul无法将客户端证书转发到后端,我认为下一个最好的方法是在Zuul的前门对用户进行身份验证,然后使用Spring会话在后端服务中复制他们的身份验证状态。我遵循了Dave Syer的教程

  • 问题内容: 如何获得服务器上所有活动的PHP会话的列表并从一个用户实例中访问它们? 激励的情况是显示站点上所有当前活动用户的列表,用户名存储在每个用户的PHP会话中。 注意:我知道我可以通过数据库(甚至文件系统)创建自己的状态,但是我正在寻找一种利用内置PHP会话机制的方法。 问题答案: 看到响应,尽管有可能,但这并不意味着您 应该 这样做。会话的存储格式没有记录,并且可能随时更改(即使在次要版本

  • 中描述的声明性基和ORM映射函数 映射器配置 是ORM的主要配置接口。配置映射后,持久性操作的主要使用接口是 Session . 会话基础 会议的作用是什么? 使用会话的基础知识 打开和关闭会话 构建begin/commit/rollback块 使用sessionmaker 查询(1.x样式) 查询(2.0样式) 添加新项目或现有项目 删除 冲洗 过期/刷新 使用任意WHERE子句更新和删除 自动