简体   繁体   English

Spring Boot rabbit mq spring.rabbitmq.listener.simple.concurrency永远不会有效

[英]Spring Boot rabbit mq spring.rabbitmq.listener.simple.concurrency never works

In SpringBoot rabbit mq project,I have the configuration like that. 在SpringBoot rabbit mq项目中,我有这样的配置。

@EnableRabbit
@Configuration
public class MQConfig {

private final String primaryQueueName;
private final String deadLetterQueueName;

@Autowired
private ConnectionFactory cachingConnectionFactory;

public MQConfig(  
                 @Value("${primaryQueue.name}")String primaryQueueName,
                 @Value("${deadLetterQueue.name}")String deadLetterQueueName){

    this.primaryQueueName=primaryQueueName;
    this.deadLetterQueueName=deadLetterQueueName;
}


@Bean
public Queue primaryQueue() {
    Map<String, Object> args = new HashMap<String, Object>();
    // The default exchange
    args.put("x-dead-letter-exchange", "");
    // Route to the incoming queue when the TTL occurs
    args.put("x-dead-letter-routing-key", deadLetterQueueName);
    // TTL 500 seconds
    args.put("x-message-ttl", 300000);
    return new Queue(primaryQueueName, false, false, false, args);
}

@Bean
public Queue deadLetterQueue() {
    return new Queue(deadLetterQueueName);
}}

And my listener looks like, 我的听众看起来像,

 @Component
public class Receiver {
 private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);

    @Autowired
    private JavaMailSender mailSender;


@RabbitListener(queues = "${primaryQueue.name}")
public void receiveMessage(SimpleMailMessage message){
    LOGGER.info("Sending email message : "+message);
    try {
        mailSender.send(message);
    }catch(Exception e) {
        LOGGER.error("Failed to deliver email",e);
        throw e;
    }

}}

So far so good, the messages come to primary queue, the consumer consumes them and they are gone to dead letter queue if for some reason the consumer is not able to consume them in given TTL 300000. 到目前为止,消息进入主队列,消费者消耗它们,如果由于某种原因消费者无法在给定的TTL 300000中消费它们,它们就会进入死信队列。

Now, I want to configure the listener even further with spring application.properties, but they have no impact on it at all. 现在,我想用spring application.properties进一步配置监听器,但它们对它没有任何影响。 Eg I set spring.rabbitmq.listener.simple.concurrency=3, still it creates a single consumer, explicitly setting it in code works however. 例如,我设置spring.rabbitmq.listener.simple.concurrency = 3,但它仍会创建一个单独的使用者,但是在代码中显式设置它。 Nether works other settings, 虚空工作其他设置,

spring.rabbitmq.listener.simple.acknowledge-mode= # Acknowledge mode of container.
spring.rabbitmq.listener.simple.auto-startup=true # Start the container automatically on startup.
spring.rabbitmq.listener.simple.concurrency= # Minimum number of consumers.
spring.rabbitmq.listener.simple.default-requeue-rejected= # Whether or not to requeue delivery failures; default `true`.
spring.rabbitmq.listener.simple.idle-event-interval= # How often idle container events should be published in milliseconds.
spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of consumers.
spring.rabbitmq.listener.simple.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used).
spring.rabbitmq.listener.simple.retry.enabled=false # Whether or not publishing retries are enabled.
spring.rabbitmq.listener.simple.retry.initial-interval=1000 # Interval between the first and second attempt to deliver a message.
spring.rabbitmq.listener.simple.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.listener.simple.retry.max-interval=10000 # Maximum interval between attempts.
spring.rabbitmq.listener.simple.retry.multiplier=1.0 # A multiplier to apply to the previous delivery retry interval.
spring.rabbitmq.listener.simple.retry.stateless=true # Whether or not retry is stateless or stateful.
spring.rabbitmq.listener.simple.transaction-size=  

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html Any ideas? https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html任何想法? Am I configuring something incorrectly ? 我配置错误了吗?

You reference the docs for the current version of Spring Boot. 您引用当前版本的Spring Boot的文档。 Is this what you are using, or something older? 这是你正在使用的,或旧的东西? This property used to be spring.rabbitmq.listener.concurrency without the "simple" in there. 这个属性曾经是spring.rabbitmq.listener.concurrency而没有“简单”。

Double check the version, for example: https://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/html/common-application-properties.html 仔细检查版本,例如: https//docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/html/common-application-properties.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM