答案 0 :(得分:0)
此stackoverflow问题可能有所帮助:How is concurrency in Spring AMQP Listener Container implemented?
快速摘录,请参阅并发':
<rabbit:listener-container connection-factory="myConnectionFactory" acknowledge="none" concurrency="10" requeue-rejected="false"> <rabbit:listener ref="myListener" queues="myQueue"/> </rabbit:listener-container>
我没有使用Spring XML配置,而是使用注释,但这是我用来限制并发使用者数量的原因:
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
// process each message one at a time
factory.setConcurrentConsumers(1);
factory.setMaxConcurrentConsumers(1);
return factory;
}