diff --git a/src/vite-api/Classes/StreamManager.cs b/src/vite-api/Classes/StreamManager.cs index 9112d0b..29eb2ea 100644 --- a/src/vite-api/Classes/StreamManager.cs +++ b/src/vite-api/Classes/StreamManager.cs @@ -54,7 +54,7 @@ public List GetAllStreams() { Name = x.Config.Name, SubjectCount = x.State.SubjectCount, - ConsumerCount = x.State.ConsumerCount, + ConsumerCount = FilterConsumers(jsm.GetConsumers(x.Config.Name).ToList()).Count, MessageCount = x.State.Messages }).ToList(); } @@ -76,7 +76,7 @@ public ExtendedStreamInfoDto GetSpecificStream(string streamName) { Name = streamInfo.Config.Name, Subjects = streamInfo.Config.Subjects, - Consumers = jsm.GetConsumerNames(streamName).ToList(), + Consumers = FilterConsumers(jsm.GetConsumers(streamName).ToList()).Select(x => x.Name).ToList(), Description = streamInfo.Config.Description, Messages = streamInfo.State.Messages, Deleted = streamInfo.State.DeletedCount, @@ -92,5 +92,18 @@ public ExtendedStreamInfoDto GetSpecificStream(string streamName) throw new ArgumentException("Given stream name or sequence number does not exist on the server"); } } + + /// + /// Filters consumers based on the date they where created. Only consumers older than 10 minutes are being kept. + /// + /// List of consumers. + /// Filtered list. + private static List FilterConsumers(IEnumerable consumers) + { + return consumers.Where(x => + DateTime.Now.Date > x.Created || + (DateTime.Now.ToUniversalTime() - x.Created.ToUniversalTime()).TotalHours >= 1 || + (DateTime.Now.ToUniversalTime() - x.Created.ToUniversalTime()).TotalMinutes > 10).ToList(); + } } }