springboot 使用rabbitmq ,多线程消费
1、配置mq消费容器
@Configuration public class RabbitMqConfig { //并发数量 public static final int DEFAULT_CONCURRENT = 20; @Bean("customContainerFactory") public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setConcurrentConsumers(DEFAULT_CONCURRENT); factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT); configurer.configure(factory, connectionFactory); return factory; } }
2、消费注解
@RabbitListener(queues = {"test-queue"}, containerFactory = "customContainerFactory")