我有一个使用web套接字和stomp的春季引导应用程序,由于我们的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,它看起来支持网络套接字(如果我读对了吗?)
我尝试过在Redis中使用spring-session,并使用/不使用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时,我可以垂直和水平地缩放应用程序吗?
谢谢
斯宾塞
发布于 2021-04-23 15:30:45
忘记更新它,stackoverflow.com.com/a/43174082/4978471解释了为什么这是不可能的。
https://stackoverflow.com/questions/63438391
复制相似问题