皇上,还记得我吗?我就是1999年那个Linux伊甸园啊-----24小时滚动更新开源资讯,全年无休!

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

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和用法参考:https://gitee.com/fuhai/jboot/tree/master/src/test/java/limitation

觉得Jboot还不错,请进入 https://gitee.com/fuhai/jboot 点击 star、fork支持。

转自 http://www.oschina.net/news/92125/jboot-1-2-3