org.springframework.jms.IllegalStateException:会话已关闭

时间:2019-04-22 06:37:56

标签: java spring apache-camel activemq

我在我的Spring Boot应用程序中使用Apache Camel和ActiveMQ。有时,它开始引发错误,表明会话已关闭。我必须重新启动应用程序才能摆脱此错误。

我浏览了一些文章,这些文章表明应用程序正在耗尽最大会话限制(默认为500)。下次发生此错误时,我将查看activemq面板以查看与连接相对应的活动会话。

这是我的配置文件:

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
        <contextScan/>
    </camelContext>

    <bean class="xy.acb.task.TaskServiceBean">
        <property name="camelContext" ref="camelContext"/>
    </bean>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" destroy-method="shutdown">
        <property name="autoStartup" value="true"/>
        <property name="connectionFactory">
            <bean class="org.apache.activemq.pool.PooledConnectionFactoryBean">
                <property name="connectionFactory">
                    <bean class="org.apache.activemq.spring.ActiveMQConnectionFactory">
                        <property name="brokerURL"
                                  value="${activemq.brokerURL:tcp://activemq:61616?daemon=true}"/>
                    </bean>
                </property>
            </bean>
        </property>
            <property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE"/>
        <property name="deliveryMode" value="1"/>
        <property name="timeToLive" value="1260000"/>
    </bean>

下面是错误跟踪:

The Session is closed; nested exception is javax.jms.IllegalStateException: The Session is closed
        ; nested exception is javax.jms.IllegalStateException: The Session is closed
        at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279)
        at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
        at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:496)
        at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:228)
        at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:431)
        at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:385)
        at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:153)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:74)
        at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:375)
        at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:343)
        at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:233)
        at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:343)
        at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:168)
        at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:119)
        at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:105)

1 个答案:

答案 0 :(得分:0)

从Activemq 5.7起,maximumActive = 500(默认值)已替换为maximumActiveSessionPerConnection属性。默认连接为8。因此,总共允许500 * 8 = 4000个会话。检查您正在使用哪个Activemq版本,然后设置正确的属性以使其正常工作。