|
server:
port: 8127
# eureka 相关配置
eureka:
client:
service-url:
defaultZone: http://eureka8123.com:8123/eureka/
instance:
appname: BlogGateway #修改Eureka上的默认描述 前面的名字
instance-id: BlogGateway8127 #修改Eureka上的默认描述 后面的名字
prefer-ip-address: true # 支持 ip 代替实例名
# 打印日志的级别 配置了看看日志感觉感觉流程。
logging:
level:
# log 级别
org.springframework.cloud.gateway: debug
#由 spring.profiles.active 的值来决定使用哪组配置
spring:
profiles:
active: simpleOne
# --- 代表分割多个配置
---
spring:
profiles: simpleOne # 简单第一个尝试
application:
name: gateway8127
cloud: # 网关配置 这样配置就代表走网关可以访问blog项目的链接(直接访问的,没有任何股过滤信息。)
gateway:
routes: # 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
- id: blog8084 # 路由标识(id:标识,具有唯一性)
uri: http://127.0.0.1:8084 # 目标服务地址(uri:地址,请求转发后的地址)
predicates: # 路由条件(predicates:断言,匹配 HTTP 请求内容)
- Path=/**
filters:
- StripPrefix=1 # 解决使用服务名无法访问的问题。
- AddRequestParameter=username,superman666666
discovery: #开启微服务名字转发 也就是根据服务名去访问不同的项目
locator:
enabled: true
---
spring:
profiles: simpleSecond # 转发指定 地址 并传入参数
application:
name: gateway8127
cloud: # 网关配置
gateway:
routes: # 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
- id: blog8084
uri: http://127.0.0.1:8084
predicates:
- Method=Get
filters:
- AddRequestParameter=username,888888888888888888888888888888888
- StripPrefix=1 # 解决使用服务名无法访问的问题。
discovery: #开启微服务名字转发 也就是根据服务名去访问不同的项目
locator:
enabled: true
---
spring:
profiles: simpleThird # 转发指定 服务 并传入参数
application:
name: gateway8127
cloud: # 网关配置
gateway:
routes: # 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
- id: blog8084
uri: lb://blog8084 # 指定转发的目标服务名称(这里填的是Blog工程的spring.application.name的内容)
predicates:
- Method=Get
filters:
- AddRequestParameter=username,888888888888888888888888888888888
- StripPrefix=1 # 解决使用服务名无法访问的问题。
discovery: #开启微服务名字转发 也就是根据服务名去访问不同的项目
locator:
enabled: true
---
spring:
profiles: simpleFourth # 配置hystrix的熔断
application:
name: gateway8127
cloud: # 网关配置
gateway:
routes: # 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
- id: blog8084
uri: lb://blog8084 # 指定转发的目标服务名称(这里填的是Blog工程的spring.application.name的内容)
predicates:
- Method=Get
filters:
- AddRequestParameter=username,888888888888888888888888888888888
- StripPrefix=1 # 解决使用服务名无法访问的问题。
- name : Hystrix
args:
name: hystrixFallback
fallbackUri: forward:/fallback
discovery: #开启微服务名字转发 也就是根据服务名去访问不同的项目
locator:
enabled: true
---
spring:
profiles: simpleFifth # 配置限流 依赖于Redis
redis: # 配置Redis的信息
host: localhost
database: 0
port: 6379
application:
name: gateway8127
cloud: # 网关配置
gateway:
routes: # 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
- id: blog8084
uri: lb://blog8084 # 指定转发的目标服务名称(这里填的是Blog工程的spring.application.name的内容)
predicates:
- Method=Get
filters:
- AddRequestParameter=username,888888888888888888888888888888888
- StripPrefix=1 # 解决使用服务名无法访问的问题。
## 限流
- name: RequestRateLimiter
args:
### 限流过滤器的 Bean 名称 # 使用SpEL表达式从Spring容器中获取Bean对象
key-resolver: '#{@uriKeyResolver}'
### 希望允许用户每秒处理多少个请求
redis-rate-limiter.replenishRate: 1
### 用户允许在一秒钟内完成的最大请求数
redis-rate-limiter.burstCapacity: 3
discovery: #开启微服务名字转发 也就是根据服务名去访问不同的项目
locator:
enabled: true
|
|