问题
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