[英]How can I run multiple listeners in Spring Boot Java?
I am continuously receiving data feed from third party and want to process around 100k messages in less than a minute.我不断收到来自第三方的数据馈送,并希望在不到一分钟的时间内处理大约 10 万条消息。 So thinking to implement a messaging queue through which I can offload the processing part and will push the message to a queue, where one worker out of 100 (or whatever number) picks the job and process it.
所以想实现一个消息队列,通过它我可以卸载处理部分,并将消息推送到一个队列,在那里 100 个(或任何数字)中的一个工作人员选择工作并处理它。
I've read about JMS and Redis based messaging, but I am not sure how to run multiple listeners.我已经阅读了基于 JMS 和 Redis 的消息传递,但我不确定如何运行多个侦听器。 The single listener is already configured.
单个侦听器已配置。
Spring JMS allows you to specify concurrency limits via a "lower-upper" String, eg "5-10", or a simple upper limit String, eg "10" (the lower limit will be 1 in this case). Spring JMS 允许您通过“下限”字符串(例如“5-10”)或简单的上限字符串(例如“10”)(在这种情况下下限为 1)来指定并发限制。
The listener container will always hold on to the minimum number of consumers (setConcurrentConsumers(int)) and will slowly scale up to the maximum number of consumers侦听器容器将始终保持最小数量的消费者 (setConcurrentConsumers(int)) 并缓慢扩展到最大数量的消费者
See:看:
[1] https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/config/DefaultJmsListenerContainerFactory.html#setConcurrency-java.lang.String- [1] https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/config/DefaultJmsListenerContainerFactory.html#setConcurrency-java.lang.String-
[2] https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/listener/DefaultMessageListenerContainer.html#setConcurrency-java.lang.String- [2] https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/listener/DefaultMessageListenerContainer.html#setConcurrency-java.lang.String-
An example in a Spring boot configuration bean: Spring boot 配置 bean 中的示例:
@Configuration
@EnableJms
public class AppConfig {
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory
= new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setConcurrency("3-10");
return factory;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.