How can I configure RabbitMQ authentication mechanism in Spring Boot?

Viewed 1110
@Configuration
@EnableRabbit
public class RabbitConfiguration {

    private static final String queueName = "3055";

    private static final String topicExchangeName = queueName + "-exchange";

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

    @Bean
    TopicExchange exchange() {
        return new TopicExchange(topicExchangeName);
    }

    @Bean
    Binding binding(Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("foo.bar.#");
    }

    @Bean
    RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory,
                                  MessageConverter messageConverter) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setMessageConverter(messageConverter);
        return rabbitTemplate;
    }

    @Bean
    MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

}

Code above is my Spring Boot Project's RabbitMQ configuration class.

However, I cannot connect the RMQ server since below error pops up every time I try to connect.

Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

The Server provider told me that I need to set the authentication mechanism to AMQPLAIN.

My question is that How can I set authentication mechanism to AMQPLAIN?

No matter how much I google, I couldn't figure out how.

1 Answers

I confirm to @Raja Anbazhagan. Check the RabbitMQ logs first. Supposedly your user credentials were guest/guest.

The easiest way to solve your problem could be to add those lines in your application.yml:

spring:
  rabbitmq:
    username: <user-name>
    password: <user-password>
Related