Exemple #1
0
        private void VisitSubject(string subject, DeliverPolicy deliverPolicy, bool headersOnly, bool ordered, Action <Msg> action)
        {
            PushSubscribeOptions pso = PushSubscribeOptions.Builder()
                                       .WithOrdered(ordered)
                                       .WithConfiguration(
                ConsumerConfiguration.Builder()
                .WithAckPolicy(AckPolicy.None)
                .WithDeliverPolicy(deliverPolicy)
                .WithHeadersOnly(headersOnly)
                .Build())
                                       .Build();

            IJetStreamPushSyncSubscription sub = js.PushSubscribeSync(subject, pso);

            try
            {
                bool  lastTimedOut = false;
                ulong pending      = sub.GetConsumerInformation().CalculatedPending;
                while (pending > 0) // no need to loop if nothing pending
                {
                    try
                    {
                        Msg m = sub.NextMessage(js.Timeout);
                        action.Invoke(m);
                        if (--pending == 0)
                        {
                            return;
                        }
                        lastTimedOut = false;
                    }
                    catch (NATSTimeoutException)
                    {
                        if (lastTimedOut)
                        {
                            return; // two timeouts in a row is enough
                        }
                        lastTimedOut = true;
                    }
                }
            }
            finally
            {
                sub.Unsubscribe();
            }
        }
Exemple #2
0
        public void TestGetConsumerInfoFromSubscription()
        {
            Context.RunInJsServer(c =>
            {
                CreateDefaultTestStream(c);

                IJetStream js = c.CreateJetStreamContext();

                IJetStreamPushSyncSubscription psync = js.PushSubscribeSync(SUBJECT);
                ConsumerInfo ci = psync.GetConsumerInformation();
                Assert.Equal(STREAM, ci.Stream);

                PullSubscribeOptions pso        = PullSubscribeOptions.Builder().WithDurable(DURABLE).Build();
                IJetStreamPullSubscription pull = js.PullSubscribe(SUBJECT, pso);
                ci = pull.GetConsumerInformation();
                Assert.Equal(STREAM, ci.Stream);
            });
        }