2018年1月4日星期四

Jboot v1.2.3 新增 J2Cache 适配及限流功能


Linuxeden 开源社区 --

Jboot 是一个基于 JFinal 和 undertow 开发的微服务框架。提供了 AOP、RPC、分布式缓存、限流、降级、熔断、统一配置中心、Opentracing 数据追踪、metrics 数据监控、分布式 session、代码生成器、shiro 安全控制、swagger api 自动生成等功能。

Jboot v1.2.3 主要更新如下:

  • 新增:JbootCache 新增 J2Cache 的支持
  • 新增:PropertyConfig 注解新增 file() 的支持,可读取任意 properties 文件
  • 新增:Jboot 默认新增限流功能
  • 新增:自定义 FixedInterceptor 功能,FixedInterceptor 在 Jfinal 体系里是一个不能被 @Clear 的拦截器
  • 优化:重命名注解 PropertieConfig 为 PropertyConfig
  • 优化:移除 ehredis 缓存的 mq 依赖,默认使用 redis 的发布订阅功能
  • 优化:重命名 HandlerInterceptor 为 FixedInterceptor
  • 优化:使用 Caffeine 全面替代 Guava Cache

备注,此版本没有 bug 修复哟 ~~~~~

使用 J2Cache 只需要 maven 添加 J2cache 的 依赖,同时配置 jboot.cache.type = j2cache 即可。

在很多高并发的场景下,使用 Jboot 做限流非常简单,具体 demo 如下:

@RequestMapping("/limitation")
public class LimitationDemo extends JbootController {


    public static void main(String[] args) {
        Jboot.run(args);
    }


    public void index() {
        renderText("render ok");
    }

    /**
     * 所有的请求,每 1 秒钟只能访问一次
     */
    @EnableRequestRateLimit(rate = 1)
    public void request() {
        renderText("request() render ok");
    }

    /**
     * 所有的请求,每 1 秒钟只能访问一次
     * 被限制的请求,自动跳转到 /limitation/request2
     */
    @EnableRequestRateLimit(rate = 1, limitAction = LimitAction.REDIRECT, limitContent = "/limitation/request2")
    public void request1() {
        renderText("request1() render ok");
    }


    public void request2() {
        renderText("request2() render ok");
    }


    /**
     * 每个用户,每 5 秒钟只能访问一次
     */
    @EnableUserRateLimit(rate = 0.2)
    public void user() {
        renderText("user() render ok");
    }

    /**
     * 每个用户,每 5 秒钟只能访问一次
     * 被限制的请求,渲染文本内容 "被限制啦"
     */
    @EnableUserRateLimit(rate = 0.2, limitAction = LimitAction.TEXT, limitContent = "被限制啦")
    public void user1() {
        renderText("user1() render ok");
    }


    /**
     * 每个 IP 地址,每 5 秒钟只能访问一次
     */
    @EnableIpRateLimit(rate = 0.2)
    public void ip() {
        renderText("ip() render ok");
    }


}

关于限流更多的 demo 和用法参考:http://ift.tt/2AroqJa

觉得 Jboot 还不错,请进入 http://ift.tt/2E5y7Qm 点击 star、fork 支持。

转自 http://ift.tt/2AoLIiJ

The post Jboot v1.2.3 新增 J2Cache 适配及限流功能 appeared first on Linuxeden开源社区.

http://ift.tt/2AoLsAh

没有评论:

发表评论