예제 #1
0
        public IList <Msg> Fetch(int batchSize, int maxWaitMillis)
        {
            DurationGtZeroRequired(maxWaitMillis, "Fetch");

            IList <Msg> messages  = new List <Msg>();
            int         batchLeft = batchSize;

            Stopwatch sw = Stopwatch.StartNew();

            Duration expires = Duration.OfMillis(
                maxWaitMillis > ExpireLessMillis
                    ? maxWaitMillis - ExpireLessMillis
                    : maxWaitMillis);

            Pull(PullRequestOptions.Builder(batchLeft).WithExpiresIn(expires).Build());

            try
            {
                // timeout > 0 process as many messages we can in that time period
                // If we get a message that either manager handles, we try again, but
                // with a shorter timeout based on what we already used up
                int timeLeft = maxWaitMillis;
                while (batchLeft > 0 && timeLeft > 0)
                {
                    Msg msg = NextMessageImpl(timeLeft);
                    if (!AnyManaged(msg))   // not managed means JS Message
                    {
                        messages.Add(msg);
                        batchLeft--;
                    }
                    // try again while we have time
                    timeLeft = maxWaitMillis - (int)sw.ElapsedMilliseconds;
                }
            }
            catch (NATSTimeoutException)
            {
                // regular timeout, just end
            }

            return(messages);
        }
예제 #2
0
 public void PullNoWait(int batchSize)
 {
     Pull(PullRequestOptions.Builder(batchSize).WithNoWait().Build());
 }
예제 #3
0
 public void PullNoWait(int batchSize, int expiresInMillis)
 {
     DurationGtZeroRequired(expiresInMillis, "NoWait Expires In");
     Pull(PullRequestOptions.Builder(batchSize).WithNoWait().WithExpiresIn(expiresInMillis).Build());
 }
예제 #4
0
 public void Pull(int batchSize)
 {
     Pull(PullRequestOptions.Builder(batchSize).Build());
 }