zuul进行rate limit
博客专区 > go4it 的博客 > 博客详情
zuul进行rate limit
go4it 发表于7个月前
zuul进行rate limit
  • 发表于 7个月前
  • 阅读 179
  • 收藏 1
  • 点赞 0
  • 评论 0

##maven

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

##配置

product:
  ribbon:
    listOfServers: 192.168.99.100:8080
zuul:
  routes:
    product:
      path: /product/**
      stripPrefix: false
  ratelimit:
    enabled: true #default false
    behind-proxy: true #default false
    policies:
      product:
        limit: 10
        refresh-interval: 120 #60 default value (in seconds)
        type: #optional
          - user
          - origin
          - url
spring:
  redis:
    timeout: 10
    database: 0
    host: 192.168.99.100
    port: 6379
    pool:
      max-active: 8
      max-idle: 8
      max-wait: -1
      min-idle: 0

##filterOrder 类似spring-core-4.3.4.RELEASE-sources.jar!/org/springframework/core/Ordered.java

    /**
	 * Useful constant for the highest precedence value.
	 * @see java.lang.Integer#MIN_VALUE
	 */
	int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;

	/**
	 * Useful constant for the lowest precedence value.
	 * @see java.lang.Integer#MAX_VALUE
	 */
	int LOWEST_PRECEDENCE = Integer.MAX_VALUE;

默认越小优先级越高,排查负数的情况下,0优先级最高

RateLimitFilter com/marcosbarbero/zuul/filters/pre/ratelimit/RateLimitFilter.java 它的order为-1,表示更先执行

##测试

wrk -t12 -c100 -d10s -T30s  --latency http://localhost:8080/product

限流结果:

workspace curl -i http://localhost:8080/product\?debug=true
HTTP/1.1 429
X-Application-Context: application
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 13000
Content-Length: 0
Date: Sun, 09 Apr 2017 06:44:02 GMT

##doc

标签: Zuul
共有 人打赏支持
粉丝 15
博文 426
码字总数 214047
×
go4it
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: