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")

  

 

posted @ 2021-03-16 10:51  介寒食  阅读(4313)  评论(0编辑  收藏  举报