Spring websockets SockJS fallback protocols are not working out of the box?

放肆的年华 提交于 2019-12-24 07:15:27

问题


I've made an app with spring boot with websockets support. Everything is working great. I'm using SockJS + Stomp. No worries. It's just working. But now I want to support the ability of SockJS use its fallback protocols. And it seems that it's not working out of the box.

Here's how I added the endpoint:

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/ws").withSockJS();
}

And that's it. No more configuraion.

And now when I disable webcokets in the brower and try to launch my app I get 404 for the transport that the SockJS is trying to use as the fallback.

See? First GET /ws/iframe.html 404 then POST /ws/**/xhr_send?t=... also 404. What does this mean? Do I have to develop something else so that SockJS fallback protocols will work?


回答1:


xhr_send endpoint returns 404 if session id is not found.

If your Websocket service is scaled to multiple instances, root cause can be that session was initiated with one instance, and other instances are not aware about it.

Possible fixes:

  • sticky sessions - route all requests from a client to the same instance
  • distributed state - share user sessions between instances


来源:https://stackoverflow.com/questions/39941610/spring-websockets-sockjs-fallback-protocols-are-not-working-out-of-the-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!