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

RabbitmqSpring IntegrationSpring Amqp

Rabbitmq Problem Overview


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

Rabbitmq Solutions


Solution 1 - Rabbitmq

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

Solution 2 - Rabbitmq

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 ".*" ".*" ".*"

Solution 3 - Rabbitmq

> 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.

Solution 4 - Rabbitmq

The error

ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

can occur if the credentials that your application is trying to use to connect to RabbitMQ are incorrect or missing.

I had this happen when the RabbitMQ credentials stored in my ASP.NET application's web.config file had a value of "" for the password instead of the actual password string value.

Solution 5 - Rabbitmq

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)

Solution 6 - Rabbitmq

New solution:

The node module can't handle : in a password properly. Even url encoded, like it would work normally, it does not work.

Don't use typicalspecial characters from an URL in the password!

Like one of the following: : . ? + %


Original, wrong answer:

The error message clearly complains about using PLAIN, it does not mean the crendentials are wrong, it means you must use encrypted data delivery (TLS) instead of plaintext.

Changing amqp:// in the connection string to amqps:// (note the s) solves this.

Solution 7 - Rabbitmq

just add login password to connect to RabbitMq

 CachingConnectionFactory connectionFactory = 
         new CachingConnectionFactory("rabbit_host");

 connectionFactory.setUsername("login");
 connectionFactory.setPassword("password");

Solution 8 - Rabbitmq

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

Solution 9 - Rabbitmq

if you use the number as your password, maybe you should try to change your password using string.

I can login using deltaqin:000000 on the website, but had this while running the program. then change the password to deltaiqn. and it works.

Solution 10 - Rabbitmq

On localhost , By default use 'amqp://guest:guest@localhost:5672'

So on a remote or hosted RabbitMQ. Let's say you have the following credentials

username: niceboy password: notnice host: goxha.com port : 1597

then the uri you should pass will be

amqp://niceboy:[email protected]:1597

following the template amqp://user:pass@host:10000

if you have a vhost you can do amqp://user:pass@host:10000/vhost where the trailing vhost will be the name of your vhost

Solution 11 - Rabbitmq

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!

Solution 12 - Rabbitmq

I was facing this issue due to empty space at the end of the password(spring.rabbitmq.password=rabbit ) in spring boot application.properties got resolved on removing the empty space. Hope this checklist helps some one facing this issue.

Solution 13 - Rabbitmq

In my case I had this error, cuz of wrongly set password (I tried to use 5672, when the actual one in my system was 5676). Maybe this will help someone to double check ports...

Solution 14 - Rabbitmq

set ConnectionFactory or Connection hostname to localhost

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJavaboyView Question on Stackoverflow
Solution 1 - RabbitmqgrepitView Answer on Stackoverflow
Solution 2 - RabbitmqR‌‌‌..View Answer on Stackoverflow
Solution 3 - RabbitmqArtem BilanView Answer on Stackoverflow
Solution 4 - RabbitmqJon SchneiderView Answer on Stackoverflow
Solution 5 - RabbitmqPeter SzantoView Answer on Stackoverflow
Solution 6 - RabbitmqDaniel W.View Answer on Stackoverflow
Solution 7 - Rabbitmqbenderalex5View Answer on Stackoverflow
Solution 8 - RabbitmqMichel van EngelenView Answer on Stackoverflow
Solution 9 - RabbitmqdianertaView Answer on Stackoverflow
Solution 10 - RabbitmqiamevansobengView Answer on Stackoverflow
Solution 11 - RabbitmqEvandro BrunassiView Answer on Stackoverflow
Solution 12 - RabbitmqMallikarjun RevgondView Answer on Stackoverflow
Solution 13 - RabbitmqVictoria AgafonovaView Answer on Stackoverflow
Solution 14 - RabbitmqwenView Answer on Stackoverflow