/// <summary>
        /// Creates a new <see cref="RequestThrottlingMiddleware"/>.
        /// </summary>
        /// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
        /// <param name="queue">The queueing strategy to use for the server.</param>
        /// <param name="options">The options for the middleware, currently containing the 'OnRejected' callback.</param>
        public RequestThrottlingMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IQueuePolicy queue, IOptions <RequestThrottlingOptions> options)
        {
            if (options.Value.OnRejected == null)
            {
                throw new ArgumentException("The value of 'options.OnRejected' must not be null.", nameof(options));
            }

            _next        = next;
            _logger      = loggerFactory.CreateLogger <RequestThrottlingMiddleware>();
            _onRejected  = options.Value.OnRejected;
            _queuePolicy = queue;
        }
Example #2
0
    public static ConcurrencyLimiterMiddleware CreateTestMiddleware(IQueuePolicy queue = null, RequestDelegate onRejected = null, RequestDelegate next = null)
    {
        var options = Options.Create(new ConcurrencyLimiterOptions
        {
            OnRejected = onRejected ?? (context => Task.CompletedTask),
        });

        return(new ConcurrencyLimiterMiddleware(
                   next: next ?? (context => Task.CompletedTask),
                   loggerFactory: NullLoggerFactory.Instance,
                   queue: queue ?? CreateQueuePolicy(1, 0),
                   options: options
                   ));
    }
Example #3
0
        public static RequestThrottlingMiddleware CreateTestMiddleware(IQueuePolicy queue = null, RequestDelegate onRejected = null, RequestDelegate next = null)
        {
            var options = Options.Create(new RequestThrottlingOptions
            {
                OnRejected = onRejected ?? (context => Task.CompletedTask),
            });

            return(new RequestThrottlingMiddleware(
                       next: next ?? (context => Task.CompletedTask),
                       loggerFactory: NullLoggerFactory.Instance,
                       queue: queue ?? CreateTailDropQueue(1, 0),
                       options: options
                       ));
        }