maven

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

配置

product:
ribbon:
listOfServers: 192.168.99.100:
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优先级最高

RateLimitFiltercom/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进行rate limit的更多相关文章

  1. 服务接口API限流 Rate Limit

    一.场景描述 很多做服务接口的人或多或少的遇到这样的场景,由于业务应用系统的负载能力有限,为了防止非预期的请求对系统压力过大而拖垮业务应用系统. 也就是面对大流量时,如何进行流量控制? 服务接口的流量 ...

  2. nginx rate limit

    nginx rate limithttps://www.topjishu.com/12139.htmlhttps://blog.csdn.net/hellow__world/article/detai ...

  3. 关于Homebrew出现GitHub API rate limit错误的解决方法

    参考博文: http://havee.me/mac/2013-12/how-to-install-and-use-homebrew.html Error: GitHub API rate limit ...

  4. java 服务接口API限流 Rate Limit

    一.场景描述 很多做服务接口的人或多或少的遇到这样的场景,由于业务应用系统的负载能力有限,为了防止非预期的请求对系统压力过大而拖垮业务应用系统. 也就是面对大流量时,如何进行流量控制? 服务接口的流量 ...

  5. 服务接口API限流 Rate Limit 续

    一.前言 上一篇文章中粗浅的介绍使用Redis和基于令牌桶算法进行对服务接口API限流,本文介绍另一种算法---漏桶算法的应用.Nginx想必大家都有所了解是一个高性能的 HTTP 和反向代理服务器, ...

  6. springcloud实践(二)之api网关:zuul

    zuul是什么? front door. API Gateway.Zuul is a JVM based router and server side load balancer by Netflix ...

  7. springboot+zuul(一)------实现自定义过滤器、动态路由、动态负载。

    参考:https://blog.csdn.net/u014091123/article/details/75433656 https://blog.csdn.net/u013815546/articl ...

  8. 高可用服务设计之二:Rate limiting 限流与降级

    <高可用服务设计之二:Rate limiting 限流与降级> <nginx限制请求之一:(ngx_http_limit_conn_module)模块> <nginx限制 ...

  9. How To Change Log Rate Limiting In Linux

    By default in Linux there are a few different mechanisms in place that may rate limit logging. These ...

随机推荐

  1. [计算机网络] TCP的拥塞控制

    引言 计算机网络中的带宽.交换结点中的缓存和处理机等,都是网络的资源.在某段时间,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就会变坏.这种情况就叫做拥塞. 拥塞控制就是防止过多 ...

  2. SpringBoot2.0(五) CORS跨域

    部分跨域 @CrossOrigin注解支持类级别,方法级别添加.可以在controller类或者方法上添加,支持部分接口跨域.在两者上都添加时,方法级别的覆盖类级别的. 属性 说明 origins 允 ...

  3. mac快速安装程序

    homebrew:mac套件管理 官网 :http://brew.sh/index_zh-cn.html macport: 官网:https://www.macports.org/

  4. Django 2.0 学习(10):Django 定制化

    定制化admin表单 通过使用admin.site.register(Question)注册Question模型,Django可以构造默认的表单.通常,可以通过对象的注册机制来告诉Django我们想要 ...

  5. poj 1018 Communication System (枚举)

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22380   Accepted:  ...

  6. jQuery全选反选实例

    1. $('#tb:checkbox').each(function(){ 每次都会执行 全选-取消操作,注意$('#tb :checkbox').prop('checked',true); tb后面 ...

  7. CentOS ACL

    ACL:访问控制列表(Access Control List). 一般来说权限是针对某一类用户设置的.例如:一个文件只有拥有者.组.其他用户三种设置方式,如果希望对某个指定的用户进行单独的权限控制,就 ...

  8. CentOS 文件搜索find

    1.文件搜索,内置的的命令是find 用法: find [查找路径] 寻找条件 操作 默认路径为当前目录:默认表达式为 -print 2.主要参数: -name 匹配名称 -perm 匹配权限(mod ...

  9. springboot2.0 集成elasticsearch,实现检索、分页、排序

    springboot整合es的方式: transport方式(7.0弃用,8.0移除) spring-data(完全当做数据库来用,无法全部支持es,内部也是基于transport,包装后使用非常简单 ...

  10. POJ3678:Katu Puzzle——题解

    http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...