BlessingCR’s Blog
BlessingCR’s Blog

WebSocket Spring gateway 转发,问题处理

1. 转发处理

Gateway 配置中

   routes:

​    - id: business-backend-orch-server-websocket # 路由的编号

​     uri: lb://business-backend-orch-server

​     predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组

​       - Path=/ws

注意 uri中也可以写为 lb:ws:

2. 拦截器处理

所有不需要用到的拦截器中,加上(但我没加,不加也行)

        if ("websocket".equals(exchange.getRequest().getHeaders().getUpgrade())) {
            return chain.filter(exchange);
        }

绝大多数情况都是鉴权拦截器中把这玩意拦截了,比如我的,

所有我用@PermitAll过滤了,

3. 依赖包问题

下面这个有的话一定不行


<!--        <dependency>-->
<!--            <groupId>javax.servlet</groupId>-->
<!--            <artifactId>javax.servlet-api</artifactId>-->
<!--        </dependency>-->

4. WebSocket连上后秒断

我这是loadbalance导致均衡到别的机器上了,别的机器没有websocket代码,加了tag以后正常

发表回复

textsms
account_circle
email

  • I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

    2 月前 回复
  • WONDERFUL Post.thanks for share..more wait .. …

    4 周前 回复
  • I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…

    14 小时前 回复

BlessingCR’s Blog

WebSocket Spring gateway 转发,问题处理
1. 转发处理 Gateway 配置中 routes: ​ - id: business-backend-orch-server-websocket # 路由的编号 ​ uri: lb://business-backend-orch-server ​ predicates: # 断言…
扫描二维码继续阅读
2024-06-07