Giter Club home page Giter Club logo

limiter's Introduction

limiter

Build Status

包括四个模块

  1. limiter-lock
  2. limiter-tokenbucket 令牌桶模块
  3. limiter-open-platform 开放平台限流器模块
  4. limiter-common 公有的类库

简单说明

  1. 可以从appkey,method,appkey+detail对开放平台接口调用进行限制,默认后者的配置会覆盖前者
  2. 整个项目即可以基于单机进行限流,也可以基于集群实现(默认使用Redis)

使用说明

  1. 配置文件参数说明

    • capacity:容量,即初始给每个桶(限制)的容量.(appkeycapacity=200表示该appkey可以在一瞬间访问200次)
    • addNum:addTimeWithMillisecond单位时间内增加的访问次数(addNum=1;addTimeWithMillisecond=2000表示2S增加1次访问次数,访问次数不能超过capacity)
    • addTimeWithMillisecond:addTimeWithMillisecond单位时间内增加addNum访问次数,单位毫秒
    • addPeriod:增加访问次数的周期,单位毫秒,如果addPeriod不填写或者addPeriod小于addTimeWithMillisecond则默认使用addTimeWithMillisecond(addPeriod=3000表示距离上次次数增加的时间超过3S,才会进行下一轮的访问次数的增加,增加数量规则由addNumaddTimeWithMillisecond决定)
  2. LimiterFacade为总入口

    • ParseService,xml解析器,用于解析配置文件
    • RuleDao,规则Dao,返回整个xml配置信息
    • ConfigCenter,令牌桶配置管理中心
    • ConfigLoad,令牌桶配置加载,将xml里面的规则转换成令牌桶的配置信息
    • LockService,锁服务,因为对令牌桶的令牌操作涉及到数据竞争,所以需要加锁(当然如果可以利用CAS的,LockService可以用空实现替换)
    • TokenBucketDao,令牌桶信息的存储
    • TokenFilledStrategy,令牌桶填充个策略,当前策略是如果如果达到令牌桶的容量则停止
  3. 运行方式

    • 在项目resources文件夹加入配置文件,参考limiter-open-platform.src.test.resources路径下的配置文件

    • 在项目中引用LimiterFacade,外部使用必须保证LimiterFacade是单例的

      LimiterFacade limiterFacade = new LimiterFacade(); limiterFacade.visit("appkey","method");

  4. maven依赖

     <repositories>
       <repository>
         <id>jitpack.io</id>
         <url>https://jitpack.io</url>
       </repository>
     </repositories>
    
     <dependency>
       <groupId>com.github.iMouseWu.limiter</groupId>
       <artifactId>limiter-open-platform</artifactId>
        <version>1.0.1</version>
     </dependency>
    

limiter's People

Contributors

imousewu avatar

Watchers

 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.