在Spring启动时动态扩展JMS使用者 [英] Dynamic scaling of JMS consumer in spring boot

查看:464
本文介绍了在Spring启动时动态扩展JMS使用者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个spring-boot应用程序,它将从activeMQ生成器读取数据。我希望客户可用的资源达到最佳状态。在我的spring-boot应用程序中,我想配置多个消费者,所有这些消费者将连接到一个队列。

I am trying to build a spring-boot application which will read data from a activeMQ producer. I want to resources available on customer to the optimum.In my spring-boot application, I want to configure multiple consumers and all these consumer will connect to a single queue.

他们是否可以动态扩展并缩减sprint-boot应用程序上的消费者?

Is their a way I can dynamically scale up and scale down the consumers on sprint-boot application?

推荐答案

您正在谈论的消费者about,是 DefaultMessageListenerContainer 的不同线程,还是 DefaultMessageListenerContainer 的不同实例?

the consumers your are talking about, are different thread of the DefaultMessageListenerContainer or different instances of DefaultMessageListenerContainer ?

您可以通过更改

org.springframework.jms.listener.DefaultMessageListenerContainer.concurrentConsumers

org.springframework.jms.listener.DefaultMessageListenerContainer.maxConcurrentConsumers
相应

更新

如果您使用多个使用者和/或线程,则需要调整prefetchPolicy。

if you work with multiple consumers and/or threads you need to adapt the prefetchPolicy.

persistent queues (default value: 1000)
non-persistent queues (default value: 1000)
persistent topics (default value: 100)
non-persistent topics (default value: Short.MAX_VALUE - 1)

所有消息都被分派给第一个连接的消费者,当另一个消息连接时他没有收到消息,所以要改变这种行为,如果你有一个队列的并发消费者,你需要将prefetchPolicy设置为低于默认值的值。例如,将此 jms.prefetchPolicy.queuePrefetch = 1 添加到activemq.xml中的uri配置中,或者将其设置在客户端URL上,如下所示

all messages was dispatched to the first connected consumer and when another one connects he don't receive messages, so to change this behavior if you have concurrent consumer for a queue you need to set prefetchPolicy to a lower value than default. for example add this jms.prefetchPolicy.queuePrefetch=1 to the uri config in activemq.xml or set it on the client url like this

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://172.16.143.99:61616?jms.prefetchPolicy.queuePrefetch=1");




建议使用大预取值以获得高性能且高
消息卷。但是,对于较低的消息量,每个
消息需要很长时间才能处理,预取应该设置为1.
这样可以确保消费者一次只处理一条消息。
但是,将预取限制设置为零将导致消费者
一次一个地轮询消息,而不是将
消息推送给消费者。

Large prefetch values are recommended for high performance with high message volumes. However, for lower message volumes, where each message takes a long time to process, the prefetch should be set to 1. This ensures that a consumer is only processing one message at a time. Specifying a prefetch limit of zero, however, will cause the consumer to poll for messages, one at a time, instead of the message being pushed to the consumer.

看看 http://activemq.apache.org/what-is-the-prefetch-limit-for.html

并且

http:// activemq。 apache.org/destination-options.html

这篇关于在Spring启动时动态扩展JMS使用者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆