Spring RMQ listener always use PLAIN auth even after configuring SSL properties

自古美人都是妖i 提交于 2019-12-11 01:13:34

问题


I have a spring boot application and I am trying to configure listeners to already existing queues. Following is what I configured in my application.yml file. I have also annotated my config class with @EnableRabbit and listener with @RabbitListener with appropriate configuration referring spring documentation.

Please note that every property has a valid default value, I have removed them before posting them here.

spring:
  rabbitmq:
    host: ${rmq_host}
    port: ${rmq_port}
    virtualHost: ${rmq_virtual_host}
    requestedHeartbeat: ${rmq_requested_heartbeat_seconds}
    listener:
      simple:
        concurrency: ${rmq_listener_config_concurrent_users}
        autoStartup: ${rmq_listener_config_auto_startup}
        acknowledge-mode: ${rmq_listener_config_ack_mode}
    ssl:
      enabled: ${rmq_ssl_enabled:true}
      keyStore: ${rmq_ssl_keystore}
      keyStorePassword: ${rmq_ssl_keystore_password}
      trustStore: ${rmq_ssl_truststore}
      trustStorePassword: ${rmq_ssl_truststore_password}

With this configuration when I try to start the application it throws below exception.

org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException: Authentication failure
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:532)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:65)
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:140)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:76)
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:527)
    ... 2 common frames omitted
Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:342)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:909)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799)
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:352)
    ... 7 common frames omitted

While writing producers, I observed the same error which was resolved by setting sasl configurations to EXTERNAL but I could do it then as I was writing configuration beans on my own, here I am trying to use out of the box support from spring.


回答1:


OK, so here is what i found. There is an open defect on spring-boot which mentions that due to unavailability of configuring sasl while using spring boot, it always uses PLAIN mode of authentication and there is a workaround which made my code work as expected. Below is the configuration class I added.

@Configuration
public class RabbitMQConfig {

    @Autowired
    private RabbitProperties rabbitProperties;

    @Autowired
    private CachingConnectionFactory cachingConnectionFactory;

    @PostConstruct
    public void init() {
        if ( rabbitProperties.getSsl().isEnabled() && rabbitProperties.getSsl().getKeyStore() != null ) {
            cachingConnectionFactory.getRabbitConnectionFactory().setSaslConfig( DefaultSaslConfig.EXTERNAL );
        }
    }

}


来源:https://stackoverflow.com/questions/53752686/spring-rmq-listener-always-use-plain-auth-even-after-configuring-ssl-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!