Active MQ停止在大量消息上调度消息

时间:2012-09-18 11:34:28

标签: spring jms activemq spring-jms

我有一个基于Spring JMS和Active MQ(5.6)的系统构建,它有大约12个Spring默认消息侦听器容器(每个最多20个并发实例)都连接到同一个活动的mq目标(队列)。

系统通过每个处理程序(容器)从发往自身的队列中获取消息,使用选择器,执行其工作,然后将消息放回队列,直到所有工作完成。

我正在进行基准测试,发送25,000条消息,每条消息需要通过9个不同的处理程序。

每次运行测试时,只有大约11300条消息通过我的所有处理程序,但是活动的MQ不再发送消息。

在我当前测试结束时,我可以看到队列的以下统计信息: 入队数:120359 出队数:106693 发货数量:106693 飞行计数:0 队列大小:13666

除非重新启动代理,否则Active MQ不再调度消息。

以下是我的active-mq配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd">

    <bean id="propertyConfigurer" class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer" />
    <!-- The <broker> element is used to configure the ActiveMQ broker. -->
    <broker xmlns="http://activemq.apache.org/schema/core"
        brokerName="jmsDeployMqBroker" dataDirectory="${java.io.tmpdir}/activemq-data"
        destroyApplicationContextOnStop="true" useJmx="true">
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry topic=">" producerFlowControl="false">
                    </policyEntry>
                    <policyEntry queue=">" producerFlowControl="false">
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <destinations>
            <queue physicalName="handlersDest"/>
            <topic physicalName="notificationsDest"  />
            <queue physicalName="ActiveMQ.DLQ" />
        </destinations>

        <!-- The managementContext is used to configure how ActiveMQ is exposed 
            in JMX. By default, ActiveMQ uses the MBean server that is started by the 
            JVM. For more information, see: http://activemq.apache.org/jmx.html -->
        <managementContext>
            <managementContext createConnector="false" />
        </managementContext>

        <!-- Configure message persistence for the broker. The default persistence 
            mechanism is the KahaDB store (identified by the kahaDB tag). For more information, 
            see: http://activemq.apache.org/persistence.html -->
        <persistenceAdapter>
            <amq:kahaPersistenceAdapter directory="${java.io.tmpdir}/activemq-data/kahadb" maxDataFileLength="1g" />
        </persistenceAdapter>

        <!-- The transport connectors expose ActiveMQ over a given protocol to 
            clients and other brokers. For more information, see: http://activemq.apache.org/configuring-transports.html -->
        <transportConnectors>
            <transportConnector name="openwire" uri="${org.apache.activemq.brokerURL}" />
        </transportConnectors>
    </broker>
</beans>

以下是我的处理程序的spring配置示例:

<jee:jndi-lookup id="connectionFactory" jndi-name="${jndi.jms.connfactory}">
        <jee:environment>
            java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
            java.naming.provider.url = ${jndi.jms.naming.url}
        </jee:environment>
    </jee:jndi-lookup>

    <!-- ID must not change as it is used in autowiring the handlers -->
    <jee:jndi-lookup id="handlersDest"  jndi-name="${jndi.docprod.queue}">
        <jee:environment>
            java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
            java.naming.provider.url = ${jndi.jms.naming.url}
            ${jndi.queue.setup}
        </jee:environment>
    </jee:jndi-lookup>

<!-- ID must not change as it is used in autowiring the handlers --> 
    <jee:jndi-lookup id="notificationsDest" jndi-name="${jndi.docprod.topic}">
            <jee:environment>
            java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
            java.naming.provider.url = ${jndi.jms.naming.url}
            ${jndi.topic.setup}
        </jee:environment>
    </jee:jndi-lookup>

    <bean id="dmsReadContainer" class="mydomain.DocProdnMessageListenerContainer"
          p:connectionFactory-ref="connectionFactory"
          p:handlerClass="mydomain.DmsReadHandler"
          p:messageListener-ref="dmsReadHandler"
          p:destination-ref="handlersDest" >
          <property name="concurrentConsumers"><value>${dmsRead.initialInstances}</value></property>
          <property name="maxConcurrentConsumers"><value>${dmsRead.maxInstances}</value></property>
          <property name="idleConsumerLimit"><value>${dmsRead.idleInstances}</value></property>
          </bean>       

    <bean id="dmsReadHandler" class="mydomain.DmsReadHandler">

    </bean>
...

ActiveMQ的日志文件没有显示任何异常情况,这表明它会停止调度。

有谁知道为什么不会发送进一步的消息或有任何进一步诊断问题的建议?

2 个答案:

答案 0 :(得分:2)

我会尝试以下方法来打开一些东西......

  1. 从默认值中增加systemUsage ...

    <systemUsage>
      <systemUsage>
        <memoryUsage><memoryUsage limit="4 gb"/></memoryUsage> <!--75% of avail heap-->
        <storeUsage><storeUsage limit="10 gb"/></storeUsage>
        <tempUsage><tempUsage limit="10 gb"/></tempUsage>
      </systemUsage>
    </systemUsage> 
    
  2. 使用JMS连接池

    <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
       <property name="maxConnections" value="8" />
       <property name="connectionFactory" ref="jmsConnectionFactory" />
    </bean>
    
  3. 切换到像这样使用kahadb ......

    <persistenceAdapter>
        <kahaDB directory="activemq-data" journalMaxFileLength="32mb" enableJournalDiskSyncs="false"/>
    </persistenceAdapter>
    
  4. 降低prefetch

    tcp://localhost:61616?jms.prefetchPolicy.all=10
    

答案 1 :(得分:1)

这似乎是activemq中的问题。

目前有一个Jira: https://issues.apache.org/jira/browse/AMQ-2745