RabbitMQ Connection refused

Viewed 22

After application started

Attempting to connect to: [localhost:5672]
2022-09-22 17:51:12.872  WARN 80292 --- [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured (Exception message: Socket closed)
2022-09-22 17:51:12.880  WARN 80292 --- [)-192.168.87.19] o.s.b.a.amqp.RabbitHealthIndicator       : Rabbit health check failed

org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:510) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:751) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:214) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2095) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2068) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]

Things not related to rabbitMQ are working

application.properties:

#RABBITMQ
spring.rabbitmq.addresses=amqp://rabbitmq:rabbitmq@localhost:5672

1 Answers
  1. try using a simple tool like telnet to check the port is open on the machine, e.g. telnet localhost 5672
  2. are you running this in a Docker container? and is RabbitMQ running on the host machine? In which case localhost identifies the container not the host, you'd need to reference the hosts IP address or some virtual name.

(Not likely to be the cause of the problem is the property settings (unless you are not posting the actual values you are using). I don't think you have the correct property names, but the host/port you say you set are the defaults anyway. I do see the reference to 127.0.0.1:5672 in the logs.)

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672

See https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/html/common-application-properties.html

Related