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

栏目: 软件资讯 · 发布时间: 8年前

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

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]


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

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

Iterative Methods for Sparse Linear Systems, Second Edition

Iterative Methods for Sparse Linear Systems, Second Edition

Yousef Saad / Society for Industrial and Applied Mathematics / 2003-04-30 / USD 102.00

Tremendous progress has been made in the scientific and engineering disciplines regarding the use of iterative methods for linear systems. The size and complexity of linear and nonlinear systems arisi......一起来看看 《Iterative Methods for Sparse Linear Systems, Second Edition》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具