Spring cloud网关gateway进行websocket路由转发规则配置

2,468 阅读1分钟

@[TOC](Spring cloud网关gateway进行websocket路由转发规则配置)


一、websocket及http路由转发规则配置

后端是普通的服务时使用http或ws的详细地址进行转发, 后端是注册到nacos上的服务时,使用lb:开头或lb:ws开头前缀加上注册服务名进行配置,如下:

spring:
  cloud:
    gateway:
      routes:
        - id: http1
          uri: "http://127.0.0.1:8081" #http转发配置,直接使用http地址使用方式1
          #url: "lb://serviceName" #http转发配置,通过nacos注册中心调用serviceName使用方式2
          predicates: 
            - Path=/**
        - id: websocket1
          uri: "ws://127.0.0.1:8081" #websocket配置,直接地址使用方式1
          #uri: "lb:ws://serviceName" #websocket配置,通过nacos注册中心调用serviceName使用方式2
          predicates: 
            - Path=/websocket