Spring websockets SockJS 回退协议不是开箱即用的吗? [英] Spring websockets SockJS fallback protocols are not working out of the box?

查看:40
本文介绍了Spring websockets SockJS 回退协议不是开箱即用的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 spring boot 制作了一个支持 websockets 的应用程序.一切都是工作得很好.我正在使用 SockJS + Stomp.不用担心.它只是工作.但现在我想支持 SockJS 使用其回退协议的能力.和似乎它不是开箱即用的.

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.

现在当我在浏览器中禁用 webcokets 并尝试启动我的应用程序时,我得到404 用于 SockJS 试图用作后备的传输.

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.

看到了吗?首先 GET/ws/iframe.html 404 然后 POST/ws/**/xhr_send?t=... 也是 404.这是什么意思?我是否必须开发其他东西以便 SockJS回退协议会起作用吗?

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?

推荐答案

如果找不到会话 ID,xhr_send 端点返回 404.

xhr_send endpoint returns 404 if session id is not found.

如果您的 Websocket 服务扩展到多个实例,根本原因可能是该会话是由一个实例启动的,而其他实例并不知道.

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.

可能的修复:

  • 粘性会话 - 将来自客户端的所有请求路由到同一个实例
  • 分布式状态 - 在实例之间共享用户会话

这篇关于Spring websockets SockJS 回退协议不是开箱即用的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆