Search code examples
microservicesspring-cloudspring-cloud-streamspring-kafkaspring-rabbit

AmqpConnectException: ConnectException: Connection refused: connect


Trying out Spring Cloud to send messages to RabbitMQ following a tutorial by Josh Long on Youtube.

OS: Windows

GIT URL: https://github.com/joshlong/bootiful-microservices/tree/master/bootiful-microservices-edgware

I imported the reservation-client, eureka-service, config-service. I was successfully able to start up all the services.

Every time I hit the service with a JSON payload, I am getting the below error message.

Input URL: http://localhost:9999/reservations Body: {"reservationName":"Dr.Who"}

Output JSON:

{
    "timestamp": 1521277278436,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.amqp.AmqpConnectException",
    "message": "java.net.ConnectException: Connection refused: connect",
    "path": "/reservations"
}

I am getting the below error in the console.

2018-03-17 02:00:43.401  INFO [reservation-client,,,] 6188 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9999
2018-03-17 02:00:43.408  INFO [reservation-client,,,] 6188 --- [           main] c.example.ReservationClientApplication   : Started ReservationClientApplication in 36.047 seconds (JVM running for 36.941)
2018-03-17 02:01:15.851  INFO [reservation-client,,,] 6188 --- [nio-9999-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-17 02:01:15.854  INFO [reservation-client,,,] 6188 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-03-17 02:01:16.034  INFO [reservation-client,,,] 6188 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 180 ms
2018-03-17 02:01:16.116  WARN [reservation-client,65c06760307f62f8,65c06760307f62f8,true] 6188 --- [nio-9999-exec-1] o.s.c.n.zuul.web.ZuulHandlerMapping      : No routes found from RouteLocator
2018-03-17 02:01:18.316 ERROR [reservation-client,65c06760307f62f8,65c06760307f62f8,true] 6188 --- [nio-9999-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : Uncaught exception thrown

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]

I am getting a connection error even if I use Kafka, instead of RabbitMQ binder.

Can somebody help? All the examples seemed to have been implemented on unix based platform. Please help.


Solution

  • It simply means you either haven't installed RabbitMQ, or it's not running on the default (localhost:5672). Same thing with Kafka, you need to install and run a broker.

    I see Josh provides a docker-compose.yml to run RabbitMQ in a docker image, or you can just install RabbitMQ as a service.