DefaultJmsListenerContainerFactory / DefaultMessageListenerContainer Dynamic Sc​​aling:它是如何工作的?

时间:2016-09-12 15:17:36

标签: spring spring-jms spring-messaging

我正在尝试让我的Spring 4 JMS应用程序在处理了大量消息后动态缩减。我目前拥有1-3个消费者的并发性,我能够看到成功扩展到最大的消费者,但是一旦消费者被创建,他们就不会消失。他们待在WAIT状态。我想知道是否有一个设置或配置使消费者在负载消退后关闭。有谁知道吗?

谢谢,

1 个答案:

答案 0 :(得分:1)

看看这个选项:

/**
 * Specify the limit for idle executions of a consumer task, not having
 * received any message within its execution. If this limit is reached,
 * the task will shut down and leave receiving to other executing tasks.
 * <p>The default is 1, closing idle resources early once a task didn't
 * receive a message. This applies to dynamic scheduling only; see the
 * {@link #setMaxConcurrentConsumers "maxConcurrentConsumers"} setting.
 * The minimum number of consumers
 * (see {@link #setConcurrentConsumers "concurrentConsumers"})
 * will be kept around until shutdown in any case.
 * <p>Within each task execution, a number of message reception attempts
 * (according to the "maxMessagesPerTask" setting) will each wait for an incoming
 * message (according to the "receiveTimeout" setting). If all of those receive
 * attempts in a given task return without a message, the task is considered
 * idle with respect to received messages. Such a task may still be rescheduled;
 * however, once it reached the specified "idleTaskExecutionLimit", it will
 * shut down (in case of dynamic scaling).
 * <p>Raise this limit if you encounter too frequent scaling up and down.
 * With this limit being higher, an idle consumer will be kept around longer,
 * avoiding the restart of a consumer once a new load of messages comes in.
 * Alternatively, specify a higher "maxMessagesPerTask" and/or "receiveTimeout" value,
 * which will also lead to idle consumers being kept around for a longer time
 * (while also increasing the average execution time of each scheduled task).
 * <p><b>This setting can be modified at runtime, for example through JMX.</b>
 * @see #setMaxMessagesPerTask
 * @see #setReceiveTimeout
 */
public void setIdleTaskExecutionLimit(int idleTaskExecutionLimit) {

您还可以通过他们的JavaDocs研究DefaultMessageListenerContainer的所有其他选项。