Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java DefaultMessageListenerContainer未缩放_Java_Spring_Jms_Scalability_Spring Jms - Fatal编程技术网

Java DefaultMessageListenerContainer未缩放

Java DefaultMessageListenerContainer未缩放,java,spring,jms,scalability,spring-jms,Java,Spring,Jms,Scalability,Spring Jms,我有一个DefaultMessageListenerContainer,它(在我看来)没有扩展。容器被定义为侦听队列,队列中有100条消息 我希望,容器可以任意长度,消息将尽可能快地被消耗(通过观察maxConcurrentConsumers配置)。所以我假设有7个消费者。(从容器启动时的2个concurrentConsumers开始)一些日志信息: activeConsumerCount: 5 concurrentConsumers: 2 scheduledConsumerCount: 5 i

我有一个DefaultMessageListenerContainer,它(在我看来)没有扩展。容器被定义为侦听队列,队列中有100条消息

我希望,容器可以任意长度,消息将尽可能快地被消耗(通过观察maxConcurrentConsumers配置)。所以我假设有7个消费者。(从容器启动时的2个concurrentConsumers开始)一些日志信息:

activeConsumerCount: 5
concurrentConsumers: 2
scheduledConsumerCount: 5
idleConsumerLimit: 1
idleTaskExecLimit: 1
maxConcurrentConsumers: 7
我的Spring配置(它的一部分):

<bean id="abstractMessageListenerContainer" class="my.package.structure.LoggingListenerContainer" abstract="true">
    <property name="connectionFactory" ref="jmscfCee" />
    <property name="maxConcurrentConsumers" value="7"/>
    <property name="receiveTimeout" value="100000" />
    <property name="concurrentConsumers" value="2" />
</bean>

<bean class="my.package.structure.LoggingListenerContainer" parent="abstractMessageListenerContainer">
    <property name="destinationName" value="MY.QUEUE" />
    <property name="messageListener" ref="myMessageListener" />
</bean>

<bean id="myMessageListener" class="my.package.structure.ListenerClass"></bean>
<bean id="jmscfCee" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL">
            <value>${jmscfCee.hostName}</value>
        </property>
</bean>

<bean id="jmscfCeeCachingConnectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory ">
    <constructor-arg ref="jmscfCee" />
    <property name="sessionCacheSize" value="10" />
</bean>
我的听众类:

public class ListenerClass implements MessageListener {


    public void onMessage(Message msg) {
           //Do some business function
    }

}
有人能帮我修改一下配置,或者给我一些关于配置的提示,或者给我解释一下容器的方法吗?(如果我误解了什么)

我正在使用ActiveMQ(在WebSphere MQ的生产环境中)进行本地测试—如果它与可伸缩性主题相关

编辑:

<bean id="abstractMessageListenerContainer" class="my.package.structure.LoggingListenerContainer" abstract="true">
    <property name="connectionFactory" ref="jmscfCee" />
    <property name="maxConcurrentConsumers" value="7"/>
    <property name="receiveTimeout" value="100000" />
    <property name="concurrentConsumers" value="2" />
</bean>

<bean class="my.package.structure.LoggingListenerContainer" parent="abstractMessageListenerContainer">
    <property name="destinationName" value="MY.QUEUE" />
    <property name="messageListener" ref="myMessageListener" />
</bean>

<bean id="myMessageListener" class="my.package.structure.ListenerClass"></bean>
<bean id="jmscfCee" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL">
            <value>${jmscfCee.hostName}</value>
        </property>
</bean>

<bean id="jmscfCeeCachingConnectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory ">
    <constructor-arg ref="jmscfCee" />
    <property name="sessionCacheSize" value="10" />
</bean>

${jmscfCee.hostName}

视情况而定。几年前,我在ActiveMQ中遇到了类似的问题,它的默认行为被大量优化为大量(数千)小消息。默认情况下,每个使用者将以1000个为一批预取消息,因此如果您有少量消息,您可能会发现它们都已在一个使用者的预取缓冲区中结束,而其他使用者则处于空闲状态

您可以在连接URI或Spring配置(如果您正在构建连接工厂的话)上使用一个函数来调优此行为

<amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost">
  <property name="prefetchPolicy">
    <amq:prefetchPolicy all="1" />
  </property>
</amq:connectionFactory>


我当时使用的ActiveMQ版本不支持0的预回迁限制(即不预回迁,每次都去代理),但文档表明现在允许这样做。

如果OP使用Spring的DefaultMessageListenerContainer,然后它使用普通的JMS API,并且不使用任何特定于ActiveMQ的东西-正确吗?我不认为这个建议会适用。没错,但最终您需要在某处配置队列名称和会话工厂,这将是您可以添加特定于代理的扩展的地方。对于ActiveMQ,您可以使用队列名称(如
MY.queue?consumer.prefetchSize=1)设置每个目的地的预回迁策略。将其添加到我的brokerurl并在我的connectionfactory中仔细检查属性。发布我的connectionfactory配置(在我的编辑中),也许这是瓶颈…您使用的是哪个版本的SpringJMS?您是否尝试在容器中设置自定义
任务执行器
?默认情况下,DefaultMessageListenerContainer似乎使用SimpleAsynctAskeExecutor,它应该只为每个任务生成新线程(从3.1.2开始),但我想知道旧版本是否可以做一些不同的事情。另外,当队列仍然包含许多消息时,您是否正在检查此日志输出?如果
idleTaskExecutionLimit
值较低,那么一旦不再需要线程,容器可能会杀死它产生的线程-在此处尝试使用更高的值。我的spring jms版本是3.1.1.RELEASE。尝试设置自定义taskexecutor-没有任何影响。如果队列上仍有大约2k或3k条消息,则行为也相同。将idleTaskExecutionLimit设置为10也不会更改任何内容。