网关Zuul限流开源项目spring-cloud-zuul-ratelimit

如果你们项目在使用Spring Cloud的Zuul作为网关,这是如果需要做限流,可以使用这个开源项目spring-cloud-zuul-ratelimit

使用简单:

1、引入依赖

        <dependency>
			<groupId>com.marcosbarbero.cloud</groupId>
			<artifactId>spring-cloud-zuul-ratelimit</artifactId>
			<version>2.2.4.RELEASE</version>
		</dependency>

 

2、yml文件中配置

zuul:
  routes:
    user:
      url: http://localhost:9090
    token:
      url: http://localhost:9090
    order:
      url: http://localhost:9080
  sensitive-headers:
  ratelimit:
    enabled: true
    repository: JPA
    default-policy-list:
    - limit: 20 
      quota: 10 
      refresh-interval: 3
      type:
        - url 
        - httpmethod

 

说明:refresh-interval是时间窗口期,limit是限制请求数,quota是请求数耗时。

上面的配置即,3秒内请求数不能超过20个,这些请求的总耗时不能超过10秒

 

 

可参看:https://www.jianshu.com/p/d165e12df1da

如果这个不能满足需求,那么看来你是需要 阿里的Sentinel

 

Sentinel Logo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章