欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > Solon Cloud Gateway 开发:熟悉 Cloud Gateway

Solon Cloud Gateway 开发:熟悉 Cloud Gateway

2025/9/25 18:15:53 来源:https://blog.csdn.net/cwzb/article/details/145341803  浏览:    关键词:Solon Cloud Gateway 开发:熟悉 Cloud Gateway

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

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

solon.cloud.gateway:discover:enabled: falseexcludedServices: - "self-service"httpClient:responseTimeout: 1800 #单位:秒routes:- id: demoindex: 0 #默认为0target: "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是否启用自动发现
- excludedServicesString[]排除服务
httpClientHttp 客户端的默认超时(单位:秒)
- connectTimeout连接超时
- requestTimeout请求超时
- responseTimeout响应超时
routesRoute[]路由
- idString标识(必选)
- indexInt顺序位
- targetURI目标(必选)
- predicatesRoutePredicateFactory检测器
- filtersRouteFilterFactory过滤器
defaultFiltersRouteFilterFactory所有路由的默认过滤器

2、配置示例

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

  • 手动配置示例
solon.app:name: demo-gatewaygroup: gatewaysolon.cloud.gateway:routes:- id: demotarget: "http://localhost:8080" #直接目标地址 或负载均衡地址 "lb://demo-service"predicates:- "Path=/demo/**"filters:- "StripPrefix=1"
  • 自动发现配置示例(需要引入 Solon Cloud Discovery 插件 )

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

solon.app:name: demo-gatewaygroup: gatewaysolon.cloud.nacos:server: "127.0.0.1:8848"   #以nacos为例solon.cloud.gateway:discover:enabled: trueexcludedServices:- "self-service-name"defaultFilters:- "StripPrefix=1"
  • 测试示例地址:
http://localhost:8080/demo/test/run?name=noear

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词