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

栏目: Java · 发布时间: 8年前

内容简介: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支持。


以上所述就是小编给大家介绍的《Jboot v1.2.3 新增 J2Cache 适配及限流功能》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Design systems

Design systems

Not all design systems are equally effective. Some can generate coherent user experiences, others produce confusing patchwork designs. Some inspire teams to contribute to them, others are neglected. S......一起来看看 《Design systems》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具