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

AmqpConnectException: ConnectException: Connection refused: connect

尝试 Spring 云按照 Josh Long 在 Youtube 上的教程将消息发送到 RabbitMQ。

OS: Windows

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

我导入了reservation-client、eureka-service、config-service。我成功地启动了所有服务。

每次我使用 JSON 负载访问服务时,都会收到以下错误消息。

输入URL: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 的平台上实现的。请帮忙。

这只是意味着您尚未安装 RabbitMQ,或者未安装在默认设置 (localhost:5672) 上 运行。 Kafka 也是一样,你需要安装 运行 一个代理。

我看到 Josh 在 docker 映像中为 运行 RabbitMQ 提供了 docker-compose.yml,或者您可以将 RabbitMQ 安装为服务。