GithubHelp home page GithubHelp logo

xxadev / opendfl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from asgard2023/opendfl

0.0 0.0 0.0 2.36 MB

opendfl Java Spring Distributed frequency limitation, In service mesh, istio mode or spring cloud mode, it is a simple solution for internal flow control or distributed management of services.

License: MIT License

JavaScript 24.55% Java 23.55% CSS 42.71% HTML 9.19% Dockerfile 0.01%

opendfl's Introduction

OpenDFL Open Distributed frequency limitation

  • Springboot,Springcloud分布式访问频率限制
  • Distributed locks分布式锁
  • 基于Redis,etcd,zookeeper
  • Spring boot, spring cloud,springmvc
  • 支持基于uri的限制,配置允许动态修改
  • 核心代码采用责任链模式,功能扩展性好
  • 支持功能可配置,不需要的功能可以关闭(limit改成-1就关闭了)
  • 支持Mysql

原理及特性

  • 基于spring拦截器,可拦截controller的所有接口
  • 频率限制:每调用一次redis incr key一次,超过限制就抛异常:频率超限。
  • 分布式锁:setnx key value(并设超时时间),成功就锁住,不成功就抛异常:任务正在执行中。
  • 可以依据自身服务能力对外进行服务限制
  • 以免服务被异常流量打死服务

功能特性

  • 支持分布式锁,同一个数据ID,同一时段内只能有一个访问
  • 支持IP白名单,用户白名单
  • 支持IP黑名单,用户黑名单
  • 支持用户访问次数限制,取不到用户,自动按用户IP限制(跨IP都算)
  • 支持单IP访问次数限制(跨用户都算)
  • 支持单用户IP数限制
  • 支持单IP用户数限制
  • 支持限制配置可见性,方便查看所有已配置的限制
  • 支持接口调用次数统计,30秒最大执行时长统计
  • 支持设备号deviceId黑名单限制
  • 支持通过验证码重置用户单个功能限制
  • 支持通过验证码重置用户所有限制
  • 支持性能监控接口,及查询(每30秒内记录执行时间最大的接口)
  • 支持资源限制:同用户同资源ID频率限制
  • 支持资源限制:同IP同资源ID频率限制

完整路线图(表示已完成,红色字体表示计划中)

maven引入方法

<dependency>
    <groupId>cn.org.opendfl</groupId>
    <artifactId>opendfl-mysql-spring-boot-starter</artifactId>
    <version>1.4</version>
</dependency>

简单使用:

1,分布式交易锁,@RequestLock注解,并支持通过yml动态修改锁时长
Support type:Redis,Zookeeper,ETCD

@GetMapping("/waitLockTest")
@RequestLock(name = "waitLockTest", time=5, errMsg = "任务%s正在执行", logType=ReqLockType.ETCD)

2,分布式频率限制,@Frequency注解模式,并支持通过yml动态修改频率限制次数

/**
 * 5秒限5次
 * 1小时限100次
 */
@GetMapping("/serverTimeFreq")
@Frequencys({
        @Frequency(time = 5, limit = 10, name = "serverTimeFreq", log = true),
        @Frequency(time = 3600, limit = 20, name = "serverTimeFreq", log = true)
})
public Long serverTimeFreq(HttpServletRequest request){
    return System.currentTimeMillis();
}

动态修改限制,见application-frequency.yml

limit:
  frequencyConfigs:
    - name: serverTimeFreq
      time: 5
      limit: 10 #改成新值
    - name: serverTimeFreq
      time: 3600
      limit: 50 #改成新值

3,分布式频频率限制,配置模式,见application-frequency.yml

limit:
  uriConfigs:
      - uri: /frequencyTest/serverTimeUri #依赖接口uri
        #限制类型(limit(默认),limitIp,userIp,ipUser,resUser,resIp)
        freqLimitType: limit
        time: 5
        limit: 8
        attrName: account
      - uri: /frequencyTest/serverTimeUri
        time: 3600
        limit: 30
        attrName: account

演示demo:

有控制台能方便查看接口信息,以及对应的限制
1,console(mysql版)示例见:http://console.mysql.opendfl.org.cn/index.html
默认账号:

  • admin/admin
  • user/user

2,console示例见:http://console.opendfl.org.cn/index.html
默认账号:

  • admin/admin
  • user/user

opendfl's People

Contributors

asgard2023 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.