AmqpConnectException:ConnectException:连接被拒绝:连接

时间:2018-03-17 09:16:50

标签: microservices spring-cloud spring-cloud-stream spring-kafka spring-rabbitmq

按照Josh Long在Youtube上的教程,尝试使用Spring Cloud向RabbitMQ发送消息。

操作系统:Windows

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

我导入了预订客户端,eureka-service,config-service。我成功地启动了所有服务。

每次我使用JSON有效负载点击服务时,都会收到以下错误消息。

输入网址:http://localhost:9999/reservations 正文:{"reservationName":"Dr.Who"}

输出JSON:

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

我在控制台中收到以下错误。

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]

即使我使用Kafka而不是RabbitMQ binder,我也会收到连接错误。

有人可以帮忙吗?所有示例似乎都已在基于unix的平台上实现。请帮忙。

1 个答案:

答案 0 :(得分:1)

它只是意味着你没有安装RabbitMQ,或者它没有运行默认值(localhost:5672)。与Kafka一样,您需要安装并运行经纪人。

我看到Josh提供了一个docker-compose.yml来在docker镜像中运行RabbitMQ,或者你可以将RabbitMQ作为服务安装。