spe*_*nce 5 long-polling cloud-foundry spring-websocket spring-session
我有一个使用 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();
}
}
Run Code Online (Sandbox Code Playgroud)
客户
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');
}
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我扩展到 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
Run Code Online (Sandbox Code Playgroud)
我一直在查看发布的其他问题,例如Tomcat 集群中的 Spring Websocket ,我实现了他们的解决方案,但没有成功。
我一直在阅读spring-session,它看起来支持网络套接字(如果我没看错的话?)。
我尝试使用spring-sessionRedis 和带/不带 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();
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的所有事情总是以同样的错误结束:
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
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么我会收到此错误?
我猜测发生这种情况是因为我正在连接到实例 1,而另一个请求正在访问另一个实例?
我可以在使用时垂直和水平缩放应用程序吗xhr-polling?
谢谢
斯彭斯
| 归档时间: |
|
| 查看次数: |
2479 次 |
| 最近记录: |