Ejemplo n.º 1
0
 /**
  * Update Builder, useful if you need to update a configuration
  * @param sc the configuration to copy
  */
 internal JetStreamConfigBuilder(JetStreamConfig jetStreamConfig)
 {
     if (jetStreamConfig != null)
     {
         Name = jetStreamConfig.Name;
         SetSubjects(jetStreamConfig.Subjects);
         this.RetentionPolicy = jetStreamConfig.RetentionPolicy;
         this.MaxConsumers    = jetStreamConfig.MaxConsumers;
         this.MaxMsgs         = jetStreamConfig.MaxMsgs;
         this.MaxBytes        = jetStreamConfig.MaxBytes;
         this.MaxAge          = TimeSpan.FromMilliseconds(NATSJetStreamDuration.OfNanos(jetStreamConfig.MaxAge).Millis);
         this.MaxMsgSize      = jetStreamConfig.MaxMsgSize;
         this.StorageType     = jetStreamConfig.StorageType;
         this.Replicas        = jetStreamConfig.Replicas;
         this.NoAck           = jetStreamConfig.NoAck;
         this.TemplateOwner   = jetStreamConfig.TemplateOwner;
         this.DiscardPolicy   = jetStreamConfig.DiscardPolicy;
         if (jetStreamConfig.DuplicateWindow.HasValue)
         {
             this.DuplicateWindow = TimeSpan.FromMilliseconds(NATSJetStreamDuration.OfNanos(jetStreamConfig.DuplicateWindow.Value).Millis);
         }
         this.Placement = jetStreamConfig.Placement;
         this.Mirror    = jetStreamConfig.Mirror;
         SetSources(jetStreamConfig.Sources);
     }
 }
Ejemplo n.º 2
0
 public StreamConfigurationBuilder(StreamConfiguration sc)
 {
     if (sc == null)
     {
         return;
     }
     _name        = sc.Name;
     _description = sc.Description;
     WithSubjects(sc.Subjects); // handles null
     _retentionPolicy   = sc.RetentionPolicy;
     _maxConsumers      = sc.MaxConsumers;
     _maxMsgs           = sc.MaxMsgs;
     _maxMsgsPerSubject = sc.MaxMsgsPerSubject;
     _maxBytes          = sc.MaxBytes;
     _maxAge            = sc.MaxAge;
     _maxMsgSize        = sc.MaxValueSize;
     _storageType       = sc.StorageType;
     _replicas          = sc.Replicas;
     _noAck             = sc.NoAck;
     _templateOwner     = sc.TemplateOwner;
     _discardPolicy     = sc.DiscardPolicy;
     _duplicateWindow   = sc.DuplicateWindow;
     _placement         = sc.Placement;
     _mirror            = sc.Mirror;
     WithSources(sc.Sources);
     _sealed      = sc.Sealed;
     _allowRollup = sc.AllowRollup;
     _denyDelete  = sc.DenyDelete;
     _denyPurge   = sc.DenyPurge;
 }
Ejemplo n.º 3
0
        public static string GetString(this DiscardPolicy discardPolicy)
        {
            switch (discardPolicy)
            {
            case DiscardPolicy.New: return("new");

            case DiscardPolicy.Old: return("old");
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static DiscardPolicy GetValueOrDefault(string value, DiscardPolicy aDefault)
        {
            if (value != null)
            {
                switch (value)
                {
                case "new": return(DiscardPolicy.New);

                case "old": return(DiscardPolicy.Old);
                }
            }

            return(aDefault);
        }
Ejemplo n.º 5
0
 private JetStreamConfig(
     string name,
     List <string> subjects,
     RetentionPolicy retentionPolicy,
     long maxConsumers,
     long maxMsgs,
     long maxBytes,
     TimeSpan maxAge,
     long maxMsgSize,
     StorageType storageType,
     int replicas,
     bool noAck,
     string templateOwner,
     DiscardPolicy discardPolicy,
     TimeSpan?duplicateWindow,
     Placement placement,
     StreamSource mirror,
     List <StreamSource> sources)
 {
     this.Name            = name;
     this.Subjects        = subjects;
     this.RetentionPolicy = retentionPolicy;
     this.MaxConsumers    = maxConsumers;
     this.MaxMsgs         = maxMsgs;
     this.MaxBytes        = maxBytes;
     this.MaxAge          = NATSJetStreamDuration.OfMillis(((long)maxAge.TotalMilliseconds)).Nanos;
     this.MaxMsgSize      = maxMsgSize;
     this.StorageType     = storageType;
     this.Replicas        = replicas;
     this.NoAck           = noAck;
     this.TemplateOwner   = templateOwner;
     this.DiscardPolicy   = discardPolicy;
     if (duplicateWindow.HasValue)
     {
         this.DuplicateWindow = NATSJetStreamDuration.OfMillis(((long)duplicateWindow.Value.TotalMilliseconds)).Nanos;
     }
     this.Placement = placement;
     this.Mirror    = mirror;
     this.Sources   = sources;
 }
Ejemplo n.º 6
0
        internal override JSONNode ToJsonNode()
        {
            JSONArray sources = new JSONArray();

            if (Sources != null)
            {
                foreach (Source s in Sources)
                {
                    sources.Add(null, s.ToJsonNode());
                }
            }
            return(new JSONObject
            {
                [ApiConstants.Retention] = RetentionPolicy.GetString(),
                [ApiConstants.Storage] = StorageType.GetString(),
                [ApiConstants.Discard] = DiscardPolicy.GetString(),
                [ApiConstants.Name] = Name,
                [ApiConstants.Description] = Description,
                [ApiConstants.Subjects] = ToArray(Subjects),
                [ApiConstants.MaxConsumers] = MaxConsumers,
                [ApiConstants.MaxMsgs] = MaxMsgs,
                [ApiConstants.MaxMsgsPerSubject] = MaxMsgsPerSubject,
                [ApiConstants.MaxBytes] = MaxBytes,
                [ApiConstants.MaxAge] = MaxAge.Nanos,
                [ApiConstants.MaxMsgSize] = MaxValueSize,
                [ApiConstants.NumReplicas] = Replicas,
                [ApiConstants.NoAck] = NoAck,
                [ApiConstants.TemplateOwner] = TemplateOwner,
                [ApiConstants.DuplicateWindow] = DuplicateWindow.Nanos,
                [ApiConstants.Placement] = Placement?.ToJsonNode(),
                [ApiConstants.Mirror] = Mirror?.ToJsonNode(),
                [ApiConstants.Sources] = sources,
                // never write sealed
                [ApiConstants.AllowRollupHdrs] = AllowRollup,
                [ApiConstants.DenyDelete] = DenyDelete,
                [ApiConstants.DenyPurge] = DenyPurge
            });
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the discard policy in the StreamConfiguration.
 /// </summary>
 /// <param name="policy">the discard policy of the StreamConfiguration</param>
 /// <returns>The StreamConfigurationBuilder</returns>
 public StreamConfigurationBuilder WithDiscardPolicy(DiscardPolicy?policy)
 {
     _discardPolicy = policy ?? DiscardPolicy.Old;
     return(this);
 }
Ejemplo n.º 8
0
 /**
  * Sets the discard policy in the NATSJetStreamConfig.
  * @param policy the discard policy of the NATSJetStreamConfig
  * @return Builder
  */
 public JetStreamConfigBuilder SetDiscardPolicy(DiscardPolicy policy)
 {
     this.DiscardPolicy = policy;
     return(this);
 }