使用Spring Cloud Gateway代理转发websocket无法获取自定义的CloseReason的解决办法

使用Spring Cloud Gateway代理转发websocket无法获取自定义的CloseReason的解决办法

链接: 参考文章1
链接: 参考文章2

项目在开发过程中需要使用长连接websocket,使用起来也比较方便,而且gateway正好支持websocet的转发,负载使用uri: lb:ws:
直接使用void close(CloseReason closeReason)是可以正常返回的,此方法并没有问题,直接连接服务不走网关可以接收消息。经过网关代理后就接收不到了,code和reason都被改写。
参考git issues中别人提出的问题发现解决办法
1、重写默认的(直接拷贝)
spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/WebsocketRoutingFilter.java

2、提高优先级

@Override
	public int getOrder() {
		// Before NettyRoutingFilter since this routes certain http requests
		return Ordered.LOWEST_PRECEDENCE - 2;
	}

3、修改

@Override
				public Mono handle(WebSocketSession proxySession) {
					Mono serverClose = proxySession.closeStatus().

你可能感兴趣的:(spring,cloud,gateway,websocket)