首页 > Java > 正文

Spring amqp - 未找到兼容的身份验证机制 - 提供服务器

PHPz
发布: 2024-02-14 08:50:09
转载
1289 人浏览过

php小编新一今天为大家介绍的是Spring AMQP,它是一种基于AMQP协议的消息传递框架。然而,有时候在使用Spring AMQP时,我们可能会遇到一个错误:“未找到兼容的身份验证机制 - 提供服务器”。这个错误提示可能会让人感到困惑,不知道应该如何解决。接下来,我们将详细解释这个错误的原因,并提供解决方案,帮助大家顺利使用Spring AMQP框架。

问题内容

我正在尝试通过外部身份验证机制将 spring boot 应用程序连接到 rabbit mq (https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl)。

我收到以下错误:

org.springframework.amqp.amqpioexception: java.io.ioexception: no compatible authentication mechanism found - server offered []
    at org.springframework.amqp.rabbit.support.rabbitexceptiontranslator.convertrabbitaccessexception(rabbitexceptiontranslator.java:70) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.createbareconnection(abstractconnectionfactory.java:594) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.connection.cachingconnectionfactory.createconnection(cachingconnectionfactory.java:687) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.connection.connectionfactoryutils.createconnection(connectionfactoryutils.java:257) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.core.rabbittemplate.doexecute(rabbittemplate.java:2225) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:2198) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:2178) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.core.rabbitadmin.getqueueinfo(rabbitadmin.java:459) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.core.rabbitadmin.getqueueproperties(rabbitadmin.java:443) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.listener.abstractmessagelistenercontainer.attemptdeclarations(abstractmessagelistenercontainer.java:1891) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.listener.abstractmessagelistenercontainer.redeclareelementsifnecessary(abstractmessagelistenercontainer.java:1858) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.listener.simplemessagelistenercontainer$asyncmessageprocessingconsumer.initialize(simplemessagelistenercontainer.java:1384) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.listener.simplemessagelistenercontainer$asyncmessageprocessingconsumer.run(simplemessagelistenercontainer.java:1230) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at java.base/java.lang.thread.run(thread.java:833) ~[na:na]
caused by: java.io.ioexception: no compatible authentication mechanism found - server offered []
    at com.rabbitmq.client.impl.amqconnection.start(amqconnection.java:343) ~[amqp-client-5.17.0.jar:5.17.0]
    at com.rabbitmq.client.connectionfactory.newconnection(connectionfactory.java:1225) ~[amqp-client-5.17.0.jar:5.17.0]
    at com.rabbitmq.client.connectionfactory.newconnection(connectionfactory.java:1173) ~[amqp-client-5.17.0.jar:5.17.0]
    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.connectaddresses(abstractconnectionfactory.java:632) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.connect(abstractconnectionfactory.java:607) ~[spring-rabbit-3.0.5.jar:3.0.5]
    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.createbareconnection(abstractconnectionfactory.java:557) ~[spring-rabbit-3.0.5.jar:3.0.5]
    ... 12 common frames omitted
登录后复制

依赖关系:

<dependency>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-starter-amqp</artifactid>
                <version>3.2.1</version>
            </dependency>
登录后复制

rabbitmq版本:rabbitmq:3.12.1-management

rabbitmq.conf 包含这些属性:

default_user=guest
default_pass=guest
listeners.tcp=none
listeners.ssl.default=5672
ssl_options.cacertfile=/etc/rabbitmq/cert/ca_bundle.pem
ssl_options.certfile=/etc/rabbitmq/cert/certificate.pem
ssl_options.keyfile=/etc/rabbitmq/cert/key.pem
ssl_options.password=pass
ssl_options.verify=verify_peer
ssl_options.fail_if_no_peer_cert=true
ssl_options.versions.1=tlsv1.2
ssl_options.depth=1
auth_mechanisms.1=external
ssl_cert_login_from=common_name
登录后复制

应用程序属性:

spring.rabbitmq.ssl.enabled=true
spring.rabbitmq.ssl.algorithm=tlsv1.2
spring.rabbitmq.ssl.key-store=keystore.p12
spring.rabbitmq.ssl.key-store-password=pass
spring.rabbitmq.ssl.key-store-type=pkcs12
spring.rabbitmq.ssl.trust-store=truststore.p12
spring.rabbitmq.ssl.trust-store-password=pass
spring.rabbitmq.ssl.trust-store-type=pkcs12
登录后复制

我声明了以下方法来包含 sasl 配置:

@Bean
  public AmqpTemplate amqpTemplate(ConnectionFactory connectionFactory) {
    CachingConnectionFactory cachingConnectionFactory = (CachingConnectionFactory) connectionFactory;
    cachingConnectionFactory.getRabbitConnectionFactory().setAutomaticRecoveryEnabled(true);
    cachingConnectionFactory.getRabbitConnectionFactory().setSaslConfig(DefaultSaslConfig.EXTERNAL);
    cachingConnectionFactory.resetConnection();

    RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingConnectionFactory);
    rabbitTemplate.setMessageConverter(converter());
    return rabbitTemplate;
  }
登录后复制

解决方法

我不确定 rabbitmq 配置端的 listeners.ssl.default=5672 是什么,但听起来您将默认的 ssl 端口覆盖到该端口。

spring boot中的逻辑是这样的:

return (optional.ofnullable(getssl().getenabled()).orelse(false)) ? default_port_secure : default_port;
登录后复制

地点:

private static final int default_port_secure = 5671;
登录后复制

因此,可能需要考虑明确提供该端口:

spring.rabbitmq.port=5672
登录后复制

您可能也不需要自定义 rabbittemplate bean,只需添加 connectionfactorycustomizer 即可将 defaultsaslconfig.external 设置为自动配置的 com.rabbitmq.client.connectionfactory

也不建议使用 setautomaticrecoveryenabled(true): https://www.php.cn/link/3c0de3fec9ab8a3df01109251f137119

以上是Spring amqp - 未找到兼容的身份验证机制 - 提供服务器的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:stackoverflow.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!