技术选型
1.网关spring co zuul 转发ws 会自动降级,替换成spring cloud gayway 即可
spring:
freemarker:
checkTemplateLocation: false
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: true
httpclient:
websocket:
max-frame-payload-length: 3000000
globalcors:
corsConfigurations:
'[/**]':
allowedHeaders: "*"
allowedMethods: "*"
allowedOrigins: "*"
allowCredentials: true
maxAge: 3600
# default-filters:
# - DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
routes:
- id: sms.sev
uri: lb://sms.sev
predicates:
- Path=/sms/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: sms.zuul.sev
uri: lb://sms.sev
predicates:
- Path=/zuul/sms/**
filters:
- StripPrefix=2
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: authx.sev
uri: lb://pms.authx.sev
predicates:
- Path=/authx/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: authx.admin
uri: lb://pms.authx.admin
predicates:
- Path=/axan/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: esign
uri: lb://esi.sev
predicates:
- Path=/esign/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: rbac
uri: lb://rbac.sev
predicates:
- Path=/rbac/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: vxchat
uri: lb://vxchat.sev
predicates:
- Path=/vxchat/**
- id: gateway
uri: lb://pms.gw.sev
predicates:
- Path=/gw/**
filters:
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: fms
uri: lb://fms.sev
predicates:
- Path=/fms/**
filters:
- StripPrefix=1
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
- id: im.sev.ws
uri: lb:ws://im.sev
predicates:
- Path=/im/ws/**
filters:
- StripPrefix=2
- id: im.sev.http
uri: lb://im.sev
predicates:
- Path=/im/http/**
filters:
- StripPrefix=2
- DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
2.后端使用底层为netty的webflux
遇到的问题
01. 网关配置跨域问题后 ws 无法访问
如上配置中注释的部分 :
# default-filters:
# - DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
注释掉,节点单独配即可
02. nginx 代理会让ws 无法保存长连接,所以需要ping-pong