第三周-R-SpringCloud Gateway-三

81 阅读1分钟

第一篇主要是自己搭建一个学习环境,并了解 基本路由规则,学习断言 Predicate

juejin.cn/post/714733…

第二篇主要是学习过滤器工厂:比如限流啥的

第二周_R-SpringCloud Gateway-二 - 掘金

路由配置

在 SpringCloud Gateway 中,配置 uri 有三种方式

  • websocket 配置方式
spring:
  cloud:
    gateway:
      routes:
        - id: gateway-test
          uri: ws://localhost:8088/
          predicates:
            - Path=/api/**
  • http 地址配置方式
spring:
  cloud:
    gateway:
      routes:
        - id: gateway-test
          uri: http://localhost:8088/
          predicates:
            - Path=/api/**
  • 注册中心配置方式
spring:
  cloud:
    gateway:
      routes:
        - id: gateway-test
          uri: lb://common-api
          predicates:
            - Path=/api/**

自己搭建肯定是 http 方式。

企业级代码肯定是注册中心配置方式:方便查看修改。这里是配置注册中心的服务名字:

image.png

到这里基本可以使用 Spring Cloud Gateway 了。由于没有实际生产的操作经验,只能根据文档照猫画虎的自己模拟以下简单的调用。以后碰到更高级的用法再继续补充。