-
Notifications
You must be signed in to change notification settings - Fork 95
porter gateway
liubao edited this page Jul 18, 2022
·
1 revision
应用网关负责进行请求转发、用户认证以及其他内容,比如解决跨站访问、设置HTTP安全消息头等。通过设置网络或者防火墙,所有的请求都必须经过网关,这样就将内部服务与外部用户隔离起来,防止内部服务被非法访问。例子使用 Spring Cloud Gateway
作为应用网关。
通过细化的方式配置每个服务的路由规则。做URL规划的时候,建议每个 @RestController
都提供 URL 前缀,并包含
版本号,比如: /v1/file
。 这样,后续进行服务拆分和合并的时候,能够更好的保持兼容。
spring:
cloud:
gateway:
routes:
- id: user-core
uri: lb://user-core
predicates:
- Path=/v1/user/**
- id: file-business
uri: lb://file-business
predicates:
- Path=/v1/file/**
- id: porter-app
uri: lb://porter-app
predicates:
- Path=/porter/**
- 启用客户端熔断
客户端熔断可以在目标微服务实例不可用(表现为网络不可达异常、返回502,503错误、超时等场景下)
servicecomb:
matchGroup:
allOperation: |
matches:
- apiPath:
prefix: "/"
instanceIsolation:
allOperation: |
minimumNumberOfCalls: 10
slidingWindowSize: 10
slidingWindowType: COUNT_BASED
failureRateThreshold: 20
order: 1