Spring AMQP + RabbitMQ 3.3.5 ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN

后端 未结 12 1462
南笙
南笙 2020-12-01 00:43

I am getting below exception

org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED

相关标签:
12条回答
  • 2020-12-01 01:06

    just add login password to connect to RabbitMq

     CachingConnectionFactory connectionFactory = 
             new CachingConnectionFactory("rabbit_host");
    
     connectionFactory.setUsername("login");
     connectionFactory.setPassword("password");
    
    0 讨论(0)
  • 2020-12-01 01:15

    user 'guest' can only connect via localhost

    That's true since RabbitMQ 3.3.x. Hence you should upgrade to the same version the client library, or just upgrade Spring AMQP to the latest version (if you use dependency managent system).

    Previous version of client used 127.0.0.1 as default value for the host option of ConnectionFactory.

    0 讨论(0)
  • 2020-12-01 01:15

    For me the solution was simple: the user name is case sensitive. Failing to use the correct caps will also lead to the error.

    0 讨论(0)
  • 2020-12-01 01:19

    To allow guest access remotely, write this

    [{rabbit, [{loopback_users, []}]}].
    

    to here

    c:\Users\[your user name]\AppData\Roaming\RabbitMQ\rabbitmq.config
    

    then restart the rabbitmq windows service (Source https://www.rabbitmq.com/access-control.html)

    0 讨论(0)
  • 2020-12-01 01:19

    I made exactly what @grepit made.

    But I had to made some changes in my Java code:

    In Producer and Receiver project I altered:

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("your-host-ip");
    factory.setUsername("username-you-created");
    factory.setPassword("username-password");
    
            
    

    Doing that, you are connecting an specific host as the user you have created. It works for me!

    0 讨论(0)
  • 2020-12-01 01:21

    To complete @cpu-100 answer,

    in case you don't want to enable/use web interface, you can create a new credentials using command line like below and use it in your code to connect to RabbitMQ.

    $ rabbitmqctl add_user YOUR_USERNAME YOUR_PASSWORD
    $ rabbitmqctl set_user_tags YOUR_USERNAME administrator
    $ rabbitmqctl set_permissions -p / YOUR_USERNAME ".*" ".*" ".*"
    
    0 讨论(0)
提交回复
热议问题