【发布时间】:2017-05-13 19:10:48
【问题描述】:
我在客户端通过 STOMP 使用 Spring Websocket 和 SockJs (v1.1.1)。我使用下面的代码创建客户端。
SockJS = require('sockjs-client')
Stomp = require('webstomp-client')
stompClient = Stomp.over(new SockJS(url))
它工作正常。但它默认使用xhr_streaming 作为传输,这对我来说是不可取的。我想把它切换到websocket tranport。
stompClient = Stomp.over(new SockJS(url, null, {transports:'websocket'}))
但是这种方法对我不起作用。它与事件有关:
code: 2000
reason: "All transports failed"
我的 Spring Websocket 配置很简单:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> {
@Override
public void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/myEndpoint").setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/");
registry.setApplicationDestinationPrefixes("/app");
}
}
xhr_streaming 面临的主要问题是每个流请求都会更新用户会话的最后访问时间(我也使用 Spring Session)。但这不是我的应用程序的理想行为。那么我该如何解决呢? websocket 运输会有帮助吗?提前致谢。
【问题讨论】:
标签: spring websocket stomp spring-websocket sockjs