赞
踩
介绍:默认情况一下,一个listener对应一个consumer。
spring:
rabbitmq:
listener:
simple:
# 最小
concurrency: 5
# 最大
max-concurrency: 10
@RabbitListener(queues = "work_queue", concurrency = "3-10")
spring:
rabbitmq:
listener:
simple:
# 预处理模式更改为每次读取1条消息,在消费者未回执确认之前,不在进行下一条消息的投送
prefetch: 3
@RabbitListener(queues = "work_queue", containerFactory = "mqCachingConnectionFactory")
定义监听器工厂类
package com.cyun.demo.rabbitmq.consumer.config; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.annotation.Resource; /** * 监听器工厂类 * * @author He PanFu * @date 2022-04-18 09:18:47 */ @Configuration public class RabbitMqConfig { @Resource private CachingConnectionFactory connectionFactory; @Bean(name = "mqCachingConnectionFactory") public SimpleRabbitListenerContainerFactory mqCachingConnectionFactory() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setConnectionFactory(connectionFactory); factory.setPrefetchCount(50); return factory; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。