網關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

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