Rabbitmq concurrent consumers in Spring boot

牧云@^-^@ 提交于 2019-12-06 10:34:34

问题


I'm using @RabbitListener annotation and SimpleRabbitListenerContainerFactory bean for parallel execution of rabbitmq messages and setting the min and max concurrent consumers in the following way :

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory());
    factory.setConcurrentConsumers(MIN_RABBIT_CONCURRENT_CONSUMERS);
    factory.setMaxConcurrentConsumers(MAX_RABBIT_CONCURRENT_CONSUMERS);
    factory.setConsecutiveActiveTrigger(1);
    factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
    return factory;
}

The min limit is 3 and the max limit is 10. With this configuration, only 3 messages are getting executed parallelly, even though there are 12 messages in the queue.

Please tell me what is wrong with the config?


回答1:


With the default configuration, a new consumer will be added every 10 seconds if the other consumers are still busy.

The algorithm (and properties to affect it) is described here.




回答2:


You can create max concurrent consumers using rabbitMQ annotation

@RabbitListener(queues = "your-queue-name", concurrency = "4")
public void customCheck(Object requestObject) {
    // process
}


来源:https://stackoverflow.com/questions/49017401/rabbitmq-concurrent-consumers-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!