'How to consume only one RabbitMQ on an application that has 3 queues?

I have a Spring Boot application that uses RabbitMQ and has 3 queues (queue1, queue2 and queue3).

In this application i have one listener, that should only listen for messages on the queue named queue1 and ignore the other 2 queues, but it is getting messages from all queues.

This is my RabbitMQ config:

@Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.host);
        connectionFactory.setPort(this.port);
        connectionFactory.setUsername(this.user);
        connectionFactory.setPassword(this.password);
        return connectionFactory;
    }

    @Bean
    SimpleMessageListenerContainer container(MessageListenerAdapter listenerAdapter) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(this.connectionFactory());
        container.setQueueNames(this.startQueueQueueName, this.printQueueQueueName, this.errorQueueQueueName);
        container.setMessageListener(listenerAdapter);
        return container;
    }

    @Bean
    MessageListenerAdapter listenerAdapter(RabbitDocumentToPrintListener receiver) {
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }

and this is my listener

public void receiveMessage(String message) throws Exception {
        this.logger.debug("Received message from Rabbit");
}

I've tried adding @RabbitListener(queues = "queue1", exclusive = true) to the listener, but it didn't work. If someone could help me making this app to consume only queue1, I'd appreciate. Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source