1

I have a RabbitMQ server like this
enter image description here

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

Luiz E.
  • 6,769
  • 10
  • 58
  • 98
  • 1
    In spring config you have `activemq.user=test` but you connects to rabbitmq, not activemq and rabbitmq logs shows that you connect under `guest` username – pinepain Nov 23 '15 at 21:21

4 Answers4

6

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

jhyot
  • 3,733
  • 1
  • 27
  • 44
Daniel Bubenheim
  • 4,043
  • 3
  • 14
  • 20
4

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
code
  • 4,073
  • 3
  • 27
  • 47
1

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
0

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

Muni
  • 53
  • 2
  • 12