Search code examples
springspring-bootrabbitmqspring-rabbitrabbitmq-exchange

RabbitMQ Access refused in Spring


I'm trying to bind a new queue to an existing exchange but I'm dealing with this error and I don't know what's the issue. I have to say that before trying to create a new queue I was able to do it in the past using this same code but now something it's not working.

Shutdown Signal: channel error; protocol method: #method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to exchange 'ex-people-updates' in vhost 'PEOPLE' refused for user 'people-consumer', class-id=40, method-id=10)

After showing this message for 5 times, then this message appears:

Broker not available; cannot force queue declarations during start: java.io.IOException

And then the app runs.

The RabbitMQ config class is as follows:

@EnableRabbit
@Configuration
public class MQConfig {


    @Value("${people.queue}")
    public String queue;

    @Value("${people.exchange}")
    public String exchange;

    @Value("${people.routingkey}")
    public List<String> routingKeys;

    @Value("${spring.rabbitmq.username}")
    private String username;

    @Value("${spring.rabbitmq.password}")
    private String password;

    @Value("${spring.rabbitmq.addresses}")
    private String address;

    @Value("${spring.rabbitmq.vhost}")
    private String vHost;



    @Bean
    public Queue queue() {
        return new Queue(queue, true, false, false);
    }


    @Bean
    Exchange myExchange() {
        return ExchangeBuilder.topicExchange(exchange).durable(true).build();
    }


    @Bean
    Declarables bindings(TopicExchange exchange, Queue queue) {
        return new Declarables(routingKeys.stream()
                .map(key -> BindingBuilder
                        .bind(queue)
                        .to(exchange)
                        .with(key))
                .collect(Collectors.toList()));
    }

    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    @Bean
    public ConnectionFactory connectionFactory() throws IOException {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
        connectionFactory.setAddresses(address);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        connectionFactory.setVirtualHost(vHost);
        connectionFactory.setPublisherReturns(true);

        return connectionFactory;
    }

    @Bean
    public AmqpAdmin amqpAdmin() throws IOException {
        return new RabbitAdmin(connectionFactory());
    }
}

Solution

  • reply-text=ACCESS_REFUSED - access to exchange 'ex-people-updates' in vhost 'PEOPLE' refused for user 'people-consumer'

    It clearly means that your user does not have (configuration) permission to bind a queue to that exchange.