It is a rate limiting library based on .Net standard.
$ dotnet add package FireflySoft.RateLimit.CoreGithub: https://github.com/bosima/FireflySoft.RateLimit
Fireflysoft.RateLimit is a rate limiting library based on .Net standard. Its core is simple and lightweight, and can flexibly meet the rate limiting needs of many scenarios.
If you need to use it in ASP.NET Core, it is recommended to install the package FireflySoft.RateLimit.AspNetCore.
Use IAlgorithm to filter every request, process the return value of Check method.
// Rule
var fixedWindowRules = new FixedWindowRule[]
{
new FixedWindowRule()
{
Id = "3",
StatWindow=TimeSpan.FromSeconds(1),
LimitNumber=30,
ExtractTarget = (request) =>
{
return (request as SimulationRequest).RequestResource;
},
CheckRuleMatching = (request) =>
{
return true;
},
}
};
// Algorithm
IAlgorithm algorithm = new InProcessFixedWindowAlgorithm(fixedWindowRules);
// Check
var result = algorithm.Check(new SimulationRequest()
{
RequestId = Guid.NewGuid().ToString(),
RequestResource = "home",
Parameters = new Dictionary<string, string>() {
{ "from","sample" },
}
});
SimulationRequest is a custom request that you can modify to any type.