Esempio n. 1
0
        internal override JSONNode ToJsonNode()
        {
            JSONObject o = new JSONObject();

            AddField(o, ApiConstants.Description, Description);
            AddField(o, ApiConstants.DurableName, Durable);
            AddField(o, ApiConstants.DeliverPolicy, DeliverPolicy.GetString());
            AddField(o, ApiConstants.DeliverSubject, DeliverSubject);
            AddField(o, ApiConstants.DeliverGroup, DeliverGroup);
            AddField(o, ApiConstants.OptStartSeq, StartSeq);
            AddField(o, ApiConstants.OptStartTime, JsonUtils.ToString(StartTime));
            AddField(o, ApiConstants.AckPolicy, AckPolicy.GetString());
            AddField(o, ApiConstants.AckWait, AckWait);
            AddField(o, ApiConstants.MaxDeliver, MaxDeliver);
            AddField(o, ApiConstants.FilterSubject, FilterSubject);
            AddField(o, ApiConstants.ReplayPolicy, ReplayPolicy.GetString());
            AddField(o, ApiConstants.SampleFreq, SampleFrequency);
            AddField(o, ApiConstants.RateLimitBps, RateLimitBps);
            AddField(o, ApiConstants.MaxAckPending, MaxAckPending);
            AddField(o, ApiConstants.IdleHeartbeat, IdleHeartbeat);
            AddField(o, ApiConstants.FlowControl, FlowControl);
            AddField(o, ApiConstants.MaxWaiting, MaxPullWaiting);
            AddField(o, ApiConstants.HeadersOnly, HeadersOnly);
            AddField(o, ApiConstants.MaxBatch, MaxBatch);
            AddField(o, ApiConstants.MaxBytes, MaxBytes);
            AddField(o, ApiConstants.MaxExpires, MaxExpires);
            AddField(o, ApiConstants.InactiveThreshold, InactiveThreshold);
            AddField(o, ApiConstants.Backoff, Backoff);

            return(o);
        }
Esempio n. 2
0
 // For the builder
 private ConsumerConfig(string durableName,
                        DeliverPolicy deliverPolicy,
                        long?startSequence,
                        DateTime?startTime,
                        AckPolicy ackPolicy,
                        long ackWait,
                        long?maxDeliver,
                        string filterSubject,
                        ReplayPolicy replayPolicy,
                        string sampleFrequency,
                        long?rateLimit,
                        string deliverSubject,
                        string deliverGroup,
                        long?maxAckPending,
                        long?heartbeat,
                        bool?flowControl)
 {
     this.DurableName     = durableName;
     this.DeliverPolicy   = deliverPolicy;
     this.StartSequence   = startSequence;
     this.StartTime       = startTime;
     this.AckPolicy       = ackPolicy;
     this.AckWait         = ackWait;
     this.MaxDeliver      = maxDeliver;
     this.FilterSubject   = filterSubject;
     this.ReplayPolicy    = replayPolicy;
     this.SampleFrequency = sampleFrequency;
     this.RateLimit       = rateLimit;
     this.DeliverSubject  = deliverSubject;
     this.DeliverGroup    = deliverGroup;
     this.MaxAckPending   = maxAckPending;
     this.Heartbeat       = heartbeat;
     this.FlowControl     = flowControl;
 }
Esempio n. 3
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();
            }
        }
Esempio n. 4
0
        public static string GetString(this DeliverPolicy deliverPolicy)
        {
            switch (deliverPolicy)
            {
            case DeliverPolicy.All:             return("all");

            case DeliverPolicy.Last:            return("last");

            case DeliverPolicy.New:             return("new");

            case DeliverPolicy.ByStartSequence: return("by_start_sequence");

            case DeliverPolicy.ByStartTime:     return("by_start_time");

            case DeliverPolicy.LastPerSubject:  return("last_per_subject");
            }
            return(null);
        }
Esempio n. 5
0
 public ConsumerConfigBuilder(ConsumerConfig consumerConfig)
 {
     this.DurableName     = consumerConfig.DurableName;
     this.DeliverPolicy   = consumerConfig.DeliverPolicy;
     this.StartSequence   = consumerConfig.StartSequence;
     this.StartTime       = consumerConfig.StartTime;
     this.AckPolicy       = consumerConfig.AckPolicy;
     this.AckWait         = consumerConfig.AckWait;
     this.MaxDeliver      = consumerConfig.MaxDeliver;
     this.FilterSubject   = consumerConfig.FilterSubject;
     this.ReplayPolicy    = consumerConfig.ReplayPolicy;
     this.SampleFrequency = consumerConfig.SampleFrequency;
     this.RateLimit       = consumerConfig.RateLimit;
     this.DeliverSubject  = consumerConfig.DeliverSubject;
     this.DeliverGroup    = consumerConfig.DeliverGroup;
     this.MaxAckPending   = consumerConfig.MaxAckPending;
     this.Heartbeat       = consumerConfig.Heartbeat;
     this.FlowControl     = consumerConfig.FlowControl;
 }
Esempio n. 6
0
 /**
  * Sets the delivery policy of the ConsumerConfiguration.
  * @param policy the delivery policy.
  * @return Builder
  */
 public ConsumerConfigBuilder SetDeliverPolicy(DeliverPolicy policy)
 {
     this.DeliverPolicy = policy;
     return(this);
 }
        public KeyValueWatchSubscription(KeyValue kv, string keyPattern,
                                         IKeyValueWatcher watcher, params KeyValueWatchOption[] watchOptions)
        {
            string subject = kv.RawKeySubject(keyPattern);

            // figure out the result options
            bool          headersOnly    = false;
            bool          includeDeletes = true;
            DeliverPolicy deliverPolicy  = DeliverPolicy.LastPerSubject;

            foreach (KeyValueWatchOption wo in watchOptions)
            {
                switch (wo)
                {
                case KeyValueWatchOption.MetaOnly: headersOnly = true; break;

                case KeyValueWatchOption.IgnoreDelete: includeDeletes = false; break;

                case KeyValueWatchOption.UpdatesOnly: deliverPolicy = DeliverPolicy.New; break;

                case KeyValueWatchOption.IncludeHistory: deliverPolicy = DeliverPolicy.All; break;
                }
            }

            if (deliverPolicy == DeliverPolicy.New)
            {
                endOfDataSent = new InterlockedBoolean(true);
                watcher.EndOfData();
            }
            else
            {
                KeyValueEntry kveCheckPending = kv._kvGetLastMessage(keyPattern);
                if (kveCheckPending == null)
                {
                    endOfDataSent = new InterlockedBoolean(true);
                    watcher.EndOfData();
                }
                else
                {
                    endOfDataSent = new InterlockedBoolean(false);
                }
            }

            PushSubscribeOptions pso = PushSubscribeOptions.Builder()
                                       .WithStream(kv.StreamName)
                                       .WithOrdered(true)
                                       .WithConfiguration(
                ConsumerConfiguration.Builder()
                .WithAckPolicy(AckPolicy.None)
                .WithDeliverPolicy(deliverPolicy)
                .WithHeadersOnly(headersOnly)
                .WithFilterSubject(subject)
                .Build())
                                       .Build();

            EventHandler <MsgHandlerEventArgs> handler = (sender, args) =>
            {
                KeyValueEntry kve = new KeyValueEntry(args.msg);
                if (includeDeletes || kve.Operation.Equals(KeyValueOperation.Put))
                {
                    watcher.Watch(kve);
                }

                if (endOfDataSent.IsFalse() && kve.Delta == 0)
                {
                    endOfDataSent.Set(true);
                    watcher.EndOfData();
                }
            };

            sub = kv.js.PushSubscribeAsync(subject, handler, false, pso);
            if (endOfDataSent.IsFalse())
            {
                ulong pending = sub.GetConsumerInformation().CalculatedPending;
                if (pending == 0)
                {
                    endOfDataSent.Set(true);
                    watcher.EndOfData();
                }
            }
        }