5

I write an app based on Spring AMQP with RabbitMQ broker (on Mac OS). I have started the rabbitMQ's server and it is accessible through the Admin Console. But when my Spring app tries to connect the queue, it gets AmqpTimeoutException. Please help me to solve this issue, I am out of options.

The important thing: a couple of times during RabbitMQ ping my Spring app established a connection, but it seemed like a coincidence. So my main suspicion is about the timeout settings, but I can't define which of them.

I tried to increase the handshake timeouts on both sides. Also, I tried the different connection settings: I changed the user from guest to test, host from 127.0.0.1 to localhost (it gives 'Connection refused').

RabbitMQ: 3.7.16, Spring AMQP: amqp-client-5.1.2, Spring Rabbit: spring-rabbit-2.0.2.RELEASE.

My rabbitmq.config:

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

Listeners rabbitmqctl status

     [{clustering,25672,"::"},
      {amqp,5672,"127.0.0.1"},
      {stomp,61613,"::"},
      {mqtt,1883,"::"},
      {http,15672,"::"}]}

The port situation

Nmap scan report for localhost (127.0.0.1)
Host is up (0.00037s latency).

PORT     STATE SERVICE
5672/tcp open  amqp

The application.properties:

spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

The code is very simple:

Spring Configuration

@Configuration
public class AppConfing {
    @Bean
    public Queue queue() {
        return new Queue("hello");
    }
}

And the queue recipient

@Component
public class Receiver {
    @RabbitListener(queues = "hello")
    public void receive(String in) {
        System.out.println(" [x] Received '" + in + "'");
    }
}

The error:

2019-07-26 13:35:47.517  INFO 89793 --- [cTaskExecutor-1] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [127.0.0.1:5672]
2019-07-26 13:35:52.533  WARN 89793 --- [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured (Exception message: Socket closed)
2019-07-26 13:35:52.538 ERROR 89793 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).

org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:74) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1810) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1784) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1765) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:324) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
Caused by: java.util.concurrent.TimeoutException: null
    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:494) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:306) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:957) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar:5.1.2]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar:5.1.2]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.2.RELEASE.jar:2.0.2.RELEASE]
    ... 9 common frames omitted

Also, I see in RabbitMQ's log that the Spring app drops connections:

2019-07-26 13:43:12.578 [warning] <0.4166.0> closing AMQP connection <0.4166.0> (127.0.0.1:50546 -> 127.0.0.1:5672):
client unexpectedly closed TCP connection

1 Answers1

0

Though I am not using Spring Boot, I ran into the same java.util.concurrent.TimeoutException, and it turned out to be an SSL issue. My RabbitMQ client was running with default settings (SSL turned off), while the server was configured with SSL on.

Once I changed the client code to call: ConnectionFactory.useSslProtocol() the issue was resolved.

With Spring Boot I believe this would mean setting:

spring.rabbitmq.ssl.enabled=true

(Note: you may also need to set the SSL algorithm: spring.rabbitmq.ssl.algorithm)

scott
  • 1,003
  • 9
  • 7