赞
踩
路由(Route)
路由是网关最基础的部分,它由一个 ID,一个目标 URI,一组断言和一组过滤器定义。如果断言为真,则路由匹配。
断言(Predicate)
Java8 中的断言函数。Spring Cloud Gateway 中的断言函数输入类型是 Spring 5.0 框架中 的 ServerWebExchange。Spring Cloud Gateway 中的断言函数允许开发者去定义匹配来自于 Http Request 中的任 何信息,比如请求头和参数等。
过滤器(Filter)
一个标准的 Spring Web Filter。Spring Cloud Gateway 中的 Filter 分为两种类型,分别是 Gateway Filter 和 Global Filter。过滤器将会对请求和响应进行处理。
Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a route, it is sent to the Gateway Web Handler. This handler runs the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line is that filters can run logic both before and after the proxy request is sent. All “pre” filter logic is executed. Then the proxy request is made. After the proxy request is made, the “post” filter logic is run.
#应用ID app: id: xxx-project-plat #端口 server: port: 8300 #服务名称 spring: application: name: base-gateway cloud: gateway: discovery: locator: enabled: false # 这个配置是默认给每个服务创建一个router,设置为false防止请求默认转发到url中包含的微服务名上 #例:/auth/**会默认转发到服务auth下,而不是转发到配置的uri lower-case-service-id: true # 微服务名称以小写形式呈现 routes: - id: base-admin #微服务路由规则 uri: lb://base-admin #负载均衡,将请求转发到注册中心的base-admin predicates: #断言,如果前端请求包含/base-admin/,则走这条规则 - Path=/base-admin/** filters: # 过滤器 /base-admin/** 转发到 uri/** - StripPrefix=1 - id: project-business uri: lb://project-business predicates: - Path=/project-business/** filters: # /project-business/** 转发到 uri/** - StripPrefix=1 #spring boot 升级到2.6.x后需要增加的配置 main: allow-circular-references: true mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER #注册到eureka注册中心 eureka: instance: prefer-ip-address: true instance-id: ${spring.cloud.client.ip-address}:${server.port} client: service-url: defaultZone: ${app.eureka.defaultZone} #集成apollo配置中心 apollo: bootstrap: enabled: true namespaces: application,txyunjdbc.yml,redis.yml,ctgproject.yml,weixin.yml,cloudflashpay.yml meta: http://project-config:8080 management: endpoint: gateway: enabled: true endpoints: web: exposure: include: gateway #禁止外界访问 Spring Cloud Gateway actuator 端点 #日志级别配置 logging: level: root: INFO cn.ctg.project.dao: DEBUG
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。