예제 #1
0
        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));
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 public LimiterHelper(Constants.MessageProcessInstruction deniedProcessInstruction)
 {
     DeniedProcessInstruction = deniedProcessInstruction;
     TotalCalls = 0;
 }
예제 #4
0
 public MessageProcessInstruction(Constants.MessageProcessInstruction value, string additionalInfo = null)
 {
     this.Value          = value;
     this.AdditionalInfo = additionalInfo;
 }