server.port = 8000
spring.application.name = gw
server.max-http-header-size = 1024
server.tomcat.uri-encoding = UTF-8
server.tomcat.max-http-post-size = 1MB
spring.servlet.multipart.enabled = true
spring.servlet.multipart.max-file-size = 20MB
spring.servlet.multipart.max-request-size = 1MB
management.endpoint.gateway.enabled = true
management.endpoints.web.exposure.include = gateway
api.request.appconfig.cachetime = 5
spring.cloud.gateway.routes[0].id = service-a
spring.cloud.gateway.routes[0].uri = lb://service-a
spring.cloud.gateway.routes[0].predicates[0] = Path=/gw/somepath/**
spring.cloud.gateway.routes[0].filters[0] = StripPrefix=2
spring.cloud.gateway.routes[0].filters[1] = PrefixPath=/somepath/gw
#针对限流的注要是这 4 行配置
spring.cloud.gateway.routes[0].filters[2].name=RequestRateLimiter
# 每个 requestedTokens 时间单位下发的令牌数
spring.cloud.gateway.routes[0].filters[2].args.redis-rate-limiter.replenishRate=10
# 令牌桶的最大容量,
spring.cloud.gateway.routes[0].filters[2].args.redis-rate-limiter.burstCapacity=20
# 每 1 秒, 如果2就是每 2 秒, 60 就是一分钟
spring.cloud.gateway.routes[0].filters[2].args.redis-rate-limiter.requestedTokens=1
#针对限流的注要是这 4 行配置
注意下 name: RequestRateLimiter, 它其实还是 RequestRateLimiterGatewayFilterFactory 来工作的,会调用工厂的 apply 方法得到一个 GatewayFilter , 可参考 spring gateway 如何为请求路由到“路由策略”_爬上树顶的博客-CSDN博客
ymal 可参考:
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.2.RELEASE/reference/html/
spring: cloud: gateway: routes: - id: requestratelimiter_route uri: https://example.org filters: - name: RequestRateLimiter args: redis-rate-limiter.replenishRate: 10 redis-rate-limiter.burstCapacity: 20 redis-rate-limiter.requestedTokens: 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)