ConcurrencyLimiterMiddleware is obsolete
ConcurrencyLimiterMiddleware and its associated methods and types have been marked as obsolete.
If you require rate-limiting capabilities, switch to the newer and more capable rate-limiting middleware that was introduced in .NET 7 (for example, RateLimiterApplicationBuilderExtensions.UseRateLimiter). The .NET 7 rate-limiting API includes a concurrency limiter and several other rate-limiting algorithms that you can apply to your application.
ASP.NET Core 8.0 Preview 4
Developers could use ConcurrencyLimiterMiddleware to control concurrency by adding a policy to dependency injection (DI) and enabling the middleware:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddStackPolicy<options => {
options.MaxConcurrentRequests = 2;
options.RequestQueueLimit = 25;
});
var app = builder.Build();
app.UseConcurrencyLimiter();
// Map endpoints.
app.Run();
If you use the Affected APIs in your code, you'll get warning CS0618
at compile time.
This change affects source compatibility.
ConcurrencyLimiterMiddleware is infrequently used and undocumented. The newer rate-limiting API has more extensive functionality.
If you're using the older ConcurrencyLimiterMiddleware, we recommend moving to the newer rate-limiting middleware. Here's an example usage of the newer API, RateLimiterApplicationBuilderExtensions.UseRateLimiter:
using Microsoft.AspNetCore.RateLimiting;
using System.Threading.RateLimiting;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseRateLimiter(new RateLimiterOptions()
.AddConcurrencyLimiter("only-one-at-a-time-stacked", (options) =>
{
options.PermitLimit = 2;
options.QueueLimit = 25;
options.QueueProcessingOrder = QueueProcessingOrder.NewestFirst;
}));
app.MapGet("/", async () =>
{
await Task.Delay(10000);
return "Hello World";
}).RequireRateLimiting("only-one-at-a-time-stacked");
app.Run();
Feedback pentru .NET
.NET este un proiect open source. Selectați un link pentru a oferi feedback: