示例#1
0
        public void Pull(PullRequestOptions pullRequestOptions)
        {
            string subj           = string.Format(JetStreamConstants.JsapiConsumerMsgNext, Stream, Consumer);
            string publishSubject = Context.PrependPrefix(subj);

            Connection.Publish(publishSubject, Subject, pullRequestOptions.Serialize());
            Connection.FlushBuffer();
        }
示例#2
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);
        }
示例#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 PullNoWait(int batchSize)
 {
     Pull(PullRequestOptions.Builder(batchSize).WithNoWait().Build());
 }
示例#5
0
 public void Pull(int batchSize)
 {
     Pull(PullRequestOptions.Builder(batchSize).Build());
 }