1

我有一个 Spring Boot 应用程序,我将其部署到 Cloud Foundry 实例 (BlueMix)。我已将 CloudAMQP 实例绑定到应用程序,并希望使用它来发送我的 STOMP 消息。我无法正确配置我的 StompBrokerRelayRegistration 类以成功连接 CloudAMP 中的 RabbitMQ 实例。我打过电话

config.enableStompBrokerRelay("/topic", "/queue");

但这试图连接到本地主机。我认为它可能会尝试使用我的 org.springframework.amqp.rabbit.connection.ConnectionFactory bean,但我想不会。

然后我尝试使用 VCAP_SERVICES 中的信息调用 setRelayHost、setRelayPort、setSystemLogin、setSystemPasscode 和 setVirtualHost。完成此操作后,Spring 似乎尝试连接到 RabbitMQ 实例,但根据日志,连接立即关闭说

对等方重置连接

. 任何人都知道我可能做错了什么?

更新

显然我使用了错误的端口。使用端口 5672 会导致立即关闭连接的行为。如果我使用端口 61613,则连接似乎已建立。但是,一旦浏览器尝试建立 websocket,就会引发以下异常

    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:649)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.apache.tomcat.websocket.WsSession.getUserPrincipal(WsSession.java:578)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.getPrincipal(StandardWebSocketSession.java:123)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.getPrincipal(WebSocketServerSockJsSession.java:73)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.messaging.StompSubProtocolHandler.afterSessionEnded(StompSubProtocolHandler.java:364)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:352)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:347)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.handler.WebSocketHandlerDecorator.afterConnectionClosed(WebSocketHandlerDecorator.java:85)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.afterConnectionClosed(LoggingWebSocketHandlerDecorator.java:71)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionClosed(ExceptionWebSocketHandlerDecorator.java:89)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.close(AbstractSockJsSession.java:289)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.handler.WebSocketSessionDecorator.close(WebSocketSessionDecorator.java:158)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:287)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:306)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at org.springframework.messaging.support.ExecutorSubscribableChannel$1.run(ExecutorSubscribableChannel.java:70)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-05-14T22:17:53.70-0400 [App/0]   OUT   at java.lang.Thread.run(Thread.java:745)

在此之上,我看到了这个警告

2014-05-14T22:17:53.69-0400 [App/0]   OUT 2014-05-15 02:17:53.698  WARN 31 --- [tboundChannel-1] o.s.w.s.m.SubProtocolWebSocketHandler    : Ignoring protocol in WebSocket session after failure to obtain it: java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
2014-05-14T22:17:53.70-0400 [App/0]   OUT 2014-05-15 02:17:53.709 ERROR 31 --- [tboundChannel-1] w.s.h.ExceptionWebSocketHandlerDecorator : Unhandled error for ExceptionWebSocketHandlerDecorator [delegate=LoggingWebSocketHandlerDecorator [delegate=org.springframework.web.socket.messaging.SubProtocolWebSocketHandler@646eb571]]

有人知道这里出了什么问题吗?

4

1 回答 1

4

弄清楚我错过了什么。除了调用 setSystemLogin 和 setSystemPasscode 之外,我还需要在 StompBrokerRelayRegistration 上调用 setClientLogin 和 setClientPasscode。完成此操作后,我从浏览器到 Cloud Foundry 上的应用程序的 WebSocket 连接正常工作,Spring 能够使用 CloudAMQP 中的 RabbitMQ 实例发送 STOMP 消息。

于 2014-05-15T13:50:04.817 回答