Switching to CloudAMQP gives com.rabbitmq.client.ShutdownSignalException

1.1k views Asked by At

As the titles says, I'm trying to switch to CloudAMQP for deployment purposes.

Application.properties look as followed:

#spring.rabbitmq.host = rabbitmq
#spring.rabbitmq.host = localhost
spring.rabbitmq.host=cow.rmq2.cloudamqp.com
spring.rabbitmq.username=vvecyvwz
spring.rabbitmq.password=mypassword

The error logs:

2022-05-15 13:48:54.656  INFO 105060 --- [ntContainer#0-2] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [cow.rmq2.cloudamqp.com:5672]
2022-05-15 13:48:54.748  WARN 105060 --- [.93.32.234:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occurred (Exception message: Socket closed)
2022-05-15 13:48:59.841  INFO 105060 --- [ntContainer#0-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@665f577: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-05-15 13:48:59.842  INFO 105060 --- [ntContainer#0-3] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [cow.rmq2.cloudamqp.com:5672]
2022-05-15 13:48:59.941  WARN 105060 --- [.93.32.234:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occurred (Exception message: Socket closed)
2022-05-15 13:48:59.941 ERROR 105060 --- [ntContainer#0-3] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).

org.springframework.amqp.AmqpIOException: java.io.IOException
    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:70) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2175) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2148) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2128) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:463) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:447) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1925) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1906) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1349) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.io.IOException: null
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:147) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:439) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1225) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1173) ~[amqp-client-5.13.1.jar:5.13.1]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615) ~[spring-rabbit-2.4.2.jar:2.4.2]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ~[spring-rabbit-2.4.2.jar:2.4.2]
    ... 12 common frames omitted
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - access to vhost '/' refused for user 'vvecyvwz', class-id=10, method-id=40)
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:502) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:293) ~[amqp-client-5.13.1.jar:5.13.1]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:141) ~[amqp-client-5.13.1.jar:5.13.1]
    ... 18 common frames omitted

Genuinely have no idea what's going wrong with my application. The host, username and password are 100% correct, I'm not sure where the problem could be.

3

There are 3 answers

1
zhrgci On

Ok so the problem was that I had to add a virtual host. Which I definitely already tried programmatically like this:

@Value("${spring.rabbitmq.host}")
    private String host;
    @Value("${spring.rabbitmq.username}")
    private String username;
    @Value("${spring.rabbitmq.password}")
    private String password;

    @Bean
    public AmqpTemplate template() {
        CachingConnectionFactory cf = new CachingConnectionFactory(host);
        cf.setUsername(username);
        cf.setPassword(password);
        cf.setVirtualHost(username);
        final RabbitTemplate rabbitTemplate = new RabbitTemplate(cf);
        rabbitTemplate.setMessageConverter(converter());
        return rabbitTemplate;
    }

But apparently this doesn't work and I had to specify it in the application.properties

0
Marky On

I had the same error when I switched to Cloud AMQP. As you mentioned, the virtual host was missing from the properties:

spring.rabbitmq.virtual-host=vvecyvwz

spring.rabbitmq.host=cow.rmq2.cloudamqp.com
spring.rabbitmq.username=vvecyvwz
spring.rabbitmq.password=mypassword
spring.rabbitmq.port=5672

or you can do like this :

spring.rabbitmq.addresses=amqps://vvecyvwz:[email protected]/vvecyvwz
0
Andrey Lebedenko On

In my case, it was due to missing the leading / of the vhost value in the config.