Imran
Imran

Reputation: 1902

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

In SpringBoot rabbit mq project,I have the configuration like that.

@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.

Now, I want to configure the listener even further with spring application.properties, but they have no impact on it at all. E.g. I set spring.rabbitmq.listener.simple.concurrency=3, still it creates a single consumer, explicitly setting it in code works however. 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? Am I configuring something incorrectly ?

Upvotes: 3

Views: 14313

Answers (1)

Robert Zahm
Robert Zahm

Reputation: 1877

You reference the docs for the current version of 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.

Double check the version, for example: https://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/html/common-application-properties.html

Upvotes: 1

Related Questions