Solon Cloud Gateway 开发:熟悉 Cloud Gateway

Solon Cloud Gateway 是基于 Solon Cloud、Vert.X 和 Solon-Rx(reactive-streams) 接口实现,响应式的接口体验。因为内置了 solon-boot-vertx ,同时也支持 常规的 web 开发。

1、完整的配置说明(对应的配置结构类为:GatewayProperties)

yaml 复制代码
solon.cloud.gateway:
  discover:
    enabled: false
    excludedServices: 
      - "self-service"
  httpClient:
      responseTimeout: 1800 #单位:秒
  routes:
    - id: demo
      index: 0 #默认为0
      target: "http://localhost:8080" # 或 "lb://user-service"
      predicates:
        - "Path=/demo/**"
      filters:
        - "StripPrefix=1"
      timeout:
         responseTimeout: 1800 #单位:秒
  defaultFilters:
    - "AddRequestHeader=Gateway-Version,1.0"

配置项说明:

主要配置项 相关类型 说明
discover 自动发现配置(基于 solon cloud discovery)
- enabled 是否启用自动发现
- excludedServices String[] 排除服务
httpClient Http 客户端的默认超时(单位:秒)
- connectTimeout 连接超时
- requestTimeout 请求超时
- responseTimeout 响应超时
routes Route[] 路由
- id String 标识(必选)
- index Int 顺序位
- target URI 目标(必选)
- predicates RoutePredicateFactory 检测器
- filters RouteFilterFactory 过滤器
defaultFilters RouteFilterFactory 所有路由的默认过滤器

2、配置示例

添加 solon-lib 和 solon-cloud-gateway 插件后就可以开始配置了。

  • 手动配置示例
yaml 复制代码
solon.app:
  name: demo-gateway
  group: gateway

solon.cloud.gateway:
  routes:
    - id: demo
      target: "http://localhost:8080" #直接目标地址 或负载均衡地址 "lb://demo-service"
      predicates:
        - "Path=/demo/**"
      filters:
        - "StripPrefix=1"

使用发现服务配置时。约定 path 的第一段为 serviceName。

yaml 复制代码
solon.app:
  name: demo-gateway
  group: gateway

solon.cloud.nacos:
  server: "127.0.0.1:8848"   #以nacos为例

solon.cloud.gateway:
  discover:
    enabled: true
    excludedServices:
      - "self-service-name"
  defaultFilters:
      - "StripPrefix=1"
相关推荐
孟陬2 小时前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端
想用offer打牌2 小时前
一站式了解四种限流算法
java·后端·go
华仔啊2 小时前
Java 开发千万别给布尔变量加 is 前缀!很容易背锅
java
也些宝3 小时前
Java单例模式:饿汉、懒汉、DCL三种实现及最佳实践
java
Nyarlathotep01134 小时前
SpringBoot Starter的用法以及原理
java·spring boot
wuwen54 小时前
WebFlux + Lettuce Reactive 中 SkyWalking 链路上下文丢失的修复实践
java
SimonKing4 小时前
GitHub 10万星的OpenCode,正在悄悄改变我们的工作流
java·后端·程序员
Seven975 小时前
虚拟线程深度解析:轻量并发编程的未来趋势
java
雨中飘荡的记忆15 小时前
ElasticJob分布式调度从入门到实战
java·后端