Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting below exception

org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

Configuration: RabbitMQ 3.3.5 on windows

On Config file in %APPDATA%\RabbitMQ\rabbit.config I have done below change as per https://www.rabbitmq.com/access-control.html

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

I also tried creating a user/pwd - test/test doesn't seem to make it work.

Tried the Steps from this post.

Other Configuration Details are as below:

Tomcat hosted Spring Application Context:

<!-- Rabbit MQ configuration Start -->     <!-- Connection Factory -->     <rabbit:connection-factory id="rabbitConnFactory" virtual-host="/" username="guest" password="guest" port="5672"/>      <!-- Spring AMQP Template -->     <rabbit:template id="rabbitTemplate" connection-factory="rabbitConnFactory" routing-key="ecl.down.queue" queue="ecl.down.queue" />      <!-- Spring AMQP Admin -->     <rabbit:admin id="admin" connection-factory="rabbitConnFactory"/>      <rabbit:queue id="ecl.down.queue" name="ecl.down.queue" />      <rabbit:direct-exchange name="ecl.down.exchange">         <rabbit:bindings>             <rabbit:binding key="ecl.down.key" queue="ecl.down.queue"/>         </rabbit:bindings>     </rabbit:direct-exchange> 

In my Controller Class

@Autowired RmqMessageSender rmqMessageSender;  //Inside a method rmqMessageSender.submitToECLDown(orderInSession.getOrderNo()); 

In My Message sender:

import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component;  @Component("messageSender") public class RmqMessageSender  {      @Autowired     AmqpTemplate                rabbitTemplate;      public void submitToRMQ(String orderId){         try{             rabbitTemplate.convertAndSend("Hello World");         } catch (Exception e){             LOGGER.error(e.getMessage());         }     }        } 

Above exception Block gives below Exception


org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.


Error Log

  =ERROR REPORT==== 7-Nov-2014::18:04:37 === closing AMQP connection <0.489.0> (10.1.XX.2XX:52298 -> 10.1.XX.2XX:5672):     {handshake_error,starting,0,                      {amqp_error,access_refused,                                  "PLAIN login refused: user 'guest' can only connect via localhost",                                  'connection.start_ok'}} 

Pls find below the pom.xml entry

        <dependency>             <groupId>org.springframework.amqp</groupId>             <artifactId>spring-rabbit</artifactId>             <version>1.3.6.RELEASE</version>         </dependency>         <dependency>             <groupId>org.springframework.integration</groupId>             <artifactId>spring-integration-amqp</artifactId>             <version>4.0.4.RELEASE</version>         </dependency> 

Please let me know if you have any thoughts/suggestions

like image 622
Javaboy Avatar asked Nov 07 '14 23:11

Javaboy


2 Answers

I am sure what Artem Bilan has explained here might be one of the reasons for this error:

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

but the solution for me was that I logged in to rabbitMQ admin page (http://localhost:15672/#/users) with the default user name and password which is guest/guest then added a new user and for that new user I enabled the permission to access it from virtual host and then used the new user name and password instead of default guest and that cleared the error.

enter image description here

like image 66
grepit Avatar answered Sep 21 '22 18:09

grepit


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 ".*" ".*" ".*" 
like image 41
R‌‌‌.. Avatar answered Sep 18 '22 18:09

R‌‌‌..