8000 GitHub - jjg0519/FlowControl: FlowControl-流控组件
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jjg0519/FlowControl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CZ-FlowControl

.Net 版本的流控服务,支持TPS、请求总数、请求延迟等流控策略。

.Net Version

.Net Core 2.1.0

Installing via NuGet

Install-Package CZ.FlowControl.Service -Version 1.0.0

API

//TPS限流
var strategy = new FlowControlStrategy(){
      ID = "TPSFC",      
      Name = "服务TPS限流",     
      StrategyType = FlowControlStrategyType.TPS,
      IntThreshold = 100,
      IsRefusedRequest = false
};

FlowControlService.FlowControl(strategy, 1);
//访问总量限流
var strategy = new FlowControlStrategy()
{
      ID = "SumFC",
      Name = "服务总访问量限流",
      Creator = "User",
      LastModifier = "User",
      CreateTime = DateTime.Now,
      LastModifyTime = DateTime.Now,
      StrategyType = FlowControlStrategyType.Sum,
      IntThreshold = 100,
      TimeSpan = FlowControlTimespan.Second,
      IsRefusedRequest = true
};

FlowControlService.FlowControl(strategy, 1);
try
{
      for (int i = 0; i < 300; i++)
      {
           FlowControlService.FlowControl(strategy, 1);
      }
}
catch (Exception e)
{
      Assert.AreEqual(e.Message, "触发流控!");
}

About

FlowControl-流控组件

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%
0