【问题标题】:How can I configure RabbitMQ authentication mechanism in Spring Boot?如何在 Spring Boot 中配置 RabbitMQ 认证机制?
【发布时间】:2020-09-02 03:07:54
【问题描述】:
@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();
    }

}

上面的代码是我的 Spring Boot Project 的 RabbitMQ 配置类。

但是,我无法连接 RMQ 服务器,因为每次尝试连接时都会弹出以下错误。

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

服务器提供商告诉我需要将身份验证机制设置为 AMQPLAIN。

我的问题是如何将身份验证机制设置为 AMQPLAIN?

无论我用多少谷歌搜索,我都无法弄清楚。

【问题讨论】:

标签: spring-boot rabbitmq


【解决方案1】:

我向@Raja Anbazhagan 确认。首先检查 RabbitMQ 日志。假设您的用户凭据是访客/访客。

解决问题的最简单方法是在application.yml 中添加这些行:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 2014-11-22
    • 2019-06-18
    • 1970-01-01
    • 2020-02-24
    • 2020-11-14
    • 2017-12-22
    相关资源
    最近更新 更多