春季启动消耗没有Stomp的SockJS

时间:2020-07-14 12:09:36

标签: spring-boot websocket sockjs

我有一个运行简单SockJS端点ws://localhost:3000/sockjs的nodejs服务器。

此服务器在该端点中发出消息。

我需要在我的Spring后端连接到该端点并收听它。

我该怎么做?

WebSocketClient wsClient = new StandardWebSocketClient();
SockJsClient sockClient = new SockJsClient(Arrays.asList(new WebSocketTransport(wsClient)));
// and now? how to start listening it... ?

解决方案

sockClient.doHandshake(new TextWebSocketHandler() {
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        // handle the message...
    }
}, uri);
sockClient.start();

现在的问题是,如果SockJS服务器重新启动,如何维护连接。

我对此进行了测试,但连接没有恢复。

0 个答案:

没有答案
相关问题