问题描述
我有一个使用web-sockets和stomp的Spring Boot应用程序,由于对我们的ISAM设置的限制,我必须使用xhr-polling
协议,并且此应用程序将托管在Pivotal Cloud Foundry (PCF)
上。
服务器
@Configuration
@EnableWebSocketMessagebroker
public class WebSocketConfig extends AbstractWebSocketMessagebrokerConfigurer {
@Override
public void configureMessagebroker(MessagebrokerRegistry registry) {
registry.enableSimplebroker("/dummy");
registry.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry
.addEndpoint("/dummyendpoint")
.setAllowedOrigins("*")
.withSockJS();
}
}
客户
var socket,client;
socket = new SockJS('http://localhost:8080/dummyendpoint');
client = Stomp.over(socket);
client.connect({},function () {
client.subscribe('/dummy/message',function (message) {
console.log('subscribed');
}
});
但是,如果我最多扩展2个实例,则web-socket
连接将开始失败:
GET localhost:8080/dummyendpoint/info -> Status 200
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr -> Status 200 OK
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr_send -> Status 204
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr_send -> Status 404
我一直在研究发布的其他问题,例如Spring Websocket in a tomcat cluster,但我实施了它们的解决方案,但没有成功。
我一直在阅读spring-session
,它似乎支持网络套接字(如果我没看错的话?)。
我已尝试将spring-session
与Redis一起使用,并且在有/没有RabbitMQ的情况下用作消息代理:
public class WebSocketConfig extends AbstractSessionWebSocketMessagebrokerConfigurer<Session>{
@Override
public void configureMessagebroker(MessagebrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry
.enableStompbrokerRelay("/topic")
.setRelayHost("localhost")
.setRelayPort(61613)
.setClientLogin("guest")
.setClientPasscode("guest");
}
@Override
public void configureStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry
.addEndpoint("/dummyendpoint")
.setAllowedOrigins("*")
.withSockJS();
}
}
我尝试过的所有操作始终都会遇到相同的错误:
GET localhost:8080/dummyendpoint/info -> Status 200
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr_streaming -> Status 200 Aborted
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr_send -> Status 204
POST localhost:8080/dummyendpoint/300/jskdncdj/xhr_send -> Status 404
有人知道我为什么收到此错误吗?
我猜是因为我正在连接到实例1,而另一个请求正在碰到另一个实例?
使用xhr-polling
时是否可以垂直和水平缩放应用程序?
谢谢
斯彭斯
解决方法
忘记更新了,stackoverflow.com/a/43174082/4978471 解释了为什么这是不可能的。