Reputation: 7229
I have a RabbitMQ server like this
When I try to connect to this server via Spring Boot amqp, I see com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
My configs are this one
# Message
spring.activemq.broker-url=tcp://127.0.0.1:5672
spring.activemq.user=test
spring.activemq.password=test
Yes, the user test can access Virtual Hosts on / and yes, I can login with test/test on RabbitMQ GUI
EDIT
Looking at the rabbitmq logs, I saw this
{handshake_error,starting,0,
{amqp_error,access_refused,
"PLAIN login refused: user 'guest' - invalid credentials",
'connection.start_ok'}}
seems like Spring is ignoring my configs and trying to connect with guest
Upvotes: 2
Views: 12806
Reputation: 4229
src/main/resources/application.yml
spring:
rabbitmq:
username: guest
password: guest
host: rabbitmq
port: 5672
virtual-host: someVirtualHost
https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html
Upvotes: 6
Reputation: 1029
Try to change your rabbitMQ configuration in spring boot properties :
spring.rabbitmq.host = 127.0.0.1
spring.rabbitmq.port = 5672
spring.rabbitmq.username = guest
spring.rabbitmq.password = guest
Upvotes: 1
Reputation: 63
Using default setting up with springboot is good but if we want to add external rabbit instance to spring container then we should follow as below
application.yml
rabbitmq:
host: 'hostname'
vhost: 'vhostname'
user: 'userName'
password: 'passwd'
port: 5672
Config class
@Configuration
public class RabbitConfig {
@Value("${rabbitmq.host}")
private String host;
@Value("${rabbitmq.vhost}")
private String vhost;
@Value("${rabbitmq.user}")
private String user;
@Value("${rabbitmq.password}")
private String password;
@Value("${rabbitmq.port}")
private int port;
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory factory = new CachingConnectionFactory();
System.out.println("rmqhost is " + host);
factory.setHost(host);
factory.setVirtualHost(vhost);
factory.setUsername(user);
factory.setPassword(password);
factory.setPort(port);
return factory;
}
@Bean
public RabbitAdmin rabbitAdmin() {
return new RabbitAdmin(connectionFactory());
}
}
and we can create Bean for either rabbitmqtemplate or rabbitmqListener
Upvotes: 0
Reputation: 4221
Spring Properties includes specific settings for RabbitMQ. Try replacing your ActiveMQ config with below.
Example:
spring.rabbitmq.host = 127.0.0.1
spring.rabbitmq.port = 5672
spring.rabbitmq.username = guest
spring.rabbitmq.password = guest
Upvotes: 4