private static WindowLimiter GetLimiter() { const int maxAllowed = 1; // number of items to process in the time window const int windowSeconds = 1; const Constants.MessageProcessInstruction deniedInstruction = Constants.MessageProcessInstruction.RequeueMessageWithDelay; return(new WindowLimiter(maxAllowed, windowSeconds, deniedInstruction)); }
/// <summary> /// Limits the number of items to be processed. It allows processing 'maxAllowed' items every 'windowSeconds' seconds and if that /// limit is exceeded then the processing instruction that should be considered is 'deniedProcessInstruction' /// </summary> /// <param name="maxAllowed">max items allowed</param> /// <param name="windowSeconds"></param> /// <param name="deniedProcessInstruction"></param> public WindowLimiter(int maxAllowed, int windowSeconds, Constants.MessageProcessInstruction deniedProcessInstruction) { if (maxAllowed <= 0 || windowSeconds <= 0) { throw new ArgumentException("Invalid parameters; cannot be 0"); } MaxAllowed = maxAllowed; WindowSeconds = windowSeconds; DeniedProcessInstruction = deniedProcessInstruction; Start = DateTime.Now; End = Start.AddSeconds(windowSeconds); }
public LimiterHelper(Constants.MessageProcessInstruction deniedProcessInstruction) { DeniedProcessInstruction = deniedProcessInstruction; TotalCalls = 0; }
public MessageProcessInstruction(Constants.MessageProcessInstruction value, string additionalInfo = null) { this.Value = value; this.AdditionalInfo = additionalInfo; }