我有一个Spring Boot应用程序,我将其部署到Cloud Foundry实例(BlueMix)。我已将CloudAMQP实例绑定到应用程序,并希望将其用于发送我的STOMP消息。我无法正确配置我的StompBrokerRelayRegistration类以成功连接CloudAMP中的RabbitMQ实例。我打电话了
config.enableStompBrokerRelay("/topic", "/queue");
但是这次尝试连接到localhost。我以为它可能会尝试使用我的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]]
任何人都知道这里出了什么问题?
答案 0 :(得分:4)
弄清楚我错过了什么。除了调用setSystemLogin和setSystemPasscode之外,我还需要在StompBrokerRelayRegistration上调用setClientLogin和setClientPasscode。执行此操作后,我从浏览器到Cloud Foundry上的应用程序的WebSocket连接正常工作,Spring可以使用CloudAMQP中的RabbitMQ实例发送STOMP消息。